/ Forums
New To The Forum? Click Here To Read The How To Guide. -- Developers Click Here.

Avatar Grab sample available (Unity)

2»

Comments

  • Rave185Rave185 Posts: 27
    Lawnmower Man (or Woman)
    metrocube said:
    Rave185 said:
    Still having trouble getting custom player avatars working though. The generic fallback avatar works, but no custom ones.
    The Unity OvrAvatar is pre-wired to personalize avatars if you set the avatar's oculusUserID to a valid user ID. There's a trick though. Because the avatar gets created in the Start() function, you have to request and receive the user ID in an Awake() function. If you try to do it in Start(), it's too late.

    Note: Even with Awake(), you can still get into a race condition because the call to get the user ID is asynchronous. You don't know how long it's gonna take.

    The new docs will be live soon with some sample code that addresses all these gotchas in a straight-forward way.

    The sample adds a new class that initializes Oculus Platform in an Awake() function, requests the ID of the logged in user, and then waits until the callback function updates the oculusUserID value of your avatar.

    1. Import the Oculus Platform SDK's unity package into your avatar project.
    2. Get a real App ID from API tab of your app in the Developer Dashboard. If you haven't made an app there, go to https://dashboard.oculus.com to set yourself up as a game dev and create your first app.
    3. Copy your App ID string into the "Rift app ID" setting in the Oculus Avatars and Oculus Platform plugins.
    4. Add this script to an empty game object:
    PlatformManager.cs 

    using UnityEngine;
    using Oculus.Avatar;
    using Oculus.Platform;
    using Oculus.Platform.Models;
    using System.Collections;

    public class PlatformManager : MonoBehaviour {
        void Awake () {
            Oculus.Platform.Core.Initialize();
            Oculus.Platform.Users.GetLoggedInUser().OnComplete(GetLoggedInUserCallback);
            Oculus.Platform.Request.RunCallbacks(); //avoids race condition with OvrAvatar.cs Start().
        }

        private void GetLoggedInUserCallback(Message<User> message) {
            if (!message.IsError) {
                OvrAvatar[] avatars = FindObjectsOfType(typeof(OvrAvatar)) as OvrAvatar[];
                foreach (OvrAvatar avatar in avatars) {
                    avatar.oculusUserID = message.Data.ID;
                }
            }
          }
      }
    Thx for the help metrocube! Didn't see what you posted before submitting my last comment. Gonna try your code now, thx a lot! ^^
  • Rave185Rave185 Posts: 27
    Lawnmower Man (or Woman)
    Alrighty Metrocube, I'm back! So I got your code put into an empty gameobject exactly the way you put it, and gave the program a gameID number, but still it's only showing the default clear hands. Do I need to view the program outside of Unity's editor for the avatar to work, or is something still messed up? Thx!
  • Rave185Rave185 Posts: 27
    Lawnmower Man (or Woman)
    Hmm... odd, thought I made another comment but it's not showing. Anyway, thanks for the help @metrocube
    ! Did everything you said, put in that new c# script on an empty and put in an ID, but for some reason it's still just showing the plain transparent hands (my hands in Home are green)
  • pjennesspjenness Posts: 652
    Neo
    They way Ive done it is start he OVR avatar disabled,

    Then run thru metrocube's stuff, then enable that avatar.
    So it hasnt had a chance to awake before the ID is grabbed

    -P
    Drift VFX Visual, Virtual , Vertical

    Want 970GTX on Macbook for good FPS?
    https://forums.oculus.com/viewtopic.php?f=26&t=17349
  • Rave185Rave185 Posts: 27
    Lawnmower Man (or Woman)
    hey @pjenness ! Ok, so I started with the avatar off and am running through metrocube's stuff, but how do I then turn the avatar back on once it's done? Do I do it in the same empty's script? Thx!
  • pjennesspjenness Posts: 652
    Neo
    If you do that stuff in awake, its possible in start it may be ready.

    If not you prob need to so some check in update to make sure there is a valid ID before activating?

    I wonder if the call for the ID triggers an event on receiving an ID..if so that is even better. You can use onEvent to know when its redy and can activate.
    Im not so good with requests and events yet, so I jsut have the flag I check during an update cycle...but it is a waster of a bool check per frame


    Most of this logic I have in my gameManager or appManager classes. That control game setting/setup stuff.

    -P
    Drift VFX Visual, Virtual , Vertical

    Want 970GTX on Macbook for good FPS?
    https://forums.oculus.com/viewtopic.php?f=26&t=17349
  • Rave185Rave185 Posts: 27
    Lawnmower Man (or Woman)
    Hmmm.... I'm a bit new to coding so not all of what you said made total sense, sorry. XD I'd like to see your script, if possible, that'd probably explain things. ^^
  • metrocubemetrocube Posts: 55 Oculus Staff
    @Rave185 , did you import the Oculus Platform SDK's Unity package into your project?  In a previous post, you said you were getting errors. Did you ever resolve that? I didn't see anywhere that you said you had, so just checking.

  • Rave185Rave185 Posts: 27
    Lawnmower Man (or Woman)
    Sorry about that! XD Yeah, I did. There aren't any errors showing now, it just still isn't showing my own hands. Just the default ones. 
  • metrocubemetrocube Posts: 55 Oculus Staff
    Hmm. When you select the LocalAvatar game object in the Hierarchy, you know how it shows an Oculus User ID field in the Inspector?  When you Play your scene, does it ever change or is it stuck at 0?
  • metrocubemetrocube Posts: 55 Oculus Staff
    Copy my myscene.unity and my PlatformManager.cs  to your Unity project's Assets folder.  Does my scene work for you?
  • Rave185Rave185 Posts: 27
    Lawnmower Man (or Woman)
    Yeah, your scene works (is playable) and the oculusID does change to a number, but the avatar's shading never changes (and is your scene set up so the avatar of yours appears in front of you? if so, thx that's super helpful!)

    I'm starting to wonder if maybe my shaders are messed up or something and the avatar can't switch for some reason. But no sure there.
  • Rave185Rave185 Posts: 27
    Lawnmower Man (or Woman)
    WEll, unfortunately I'm gonna have to start again from scratch with everything I've done up to this point, cause the hard drive I stored all my project files on just decided to up and die on me even though I just bought it like a  month ago... yay... Luckily I have another hard drive with windows still installed on it, so I should be able to get going again pretty quick, but I think I'll start with you're project this time and go from there.
  • InceptionGuyInceptionGuy Posts: 2
    Virtual Boy (or Girl)
    edited February 19
    I have two issues:
    1) The default avatars is plane - white shaded. There is no semi-transparent blue shading. This is even though I have added the 3 shaders to the preloaded assets.
    2) Even though I have made sure OVRavatar's Start() is called after I get a userID - the local and remote avatars are still white shaded.
    @metrocube - I have tried running the myscene + PlatformManager.cs and it too does not show the shading and custom data. Note the shading is not semi-transparent in any state: whether I have a default user or custom one.

  • haijunhaijun Posts: 1
    Virtual Boy (or Girl)
    I am having trouble getting this working. I see my hands in VR but I couldn't grab the objects. My objects also look different from what have been posted here. All the objects in my scene are grey. Any ideas?
  • InceptionGuyInceptionGuy Posts: 2
    Virtual Boy (or Girl)
    Ok, my case has risen from two issues:
    1) We do not want to have the OVRAvatar folder within Unity under the main "Asset" folder. But changing the default location resulted in the shaders not compiling due to the #include "Assets/OvrAvatar/Content/Materials/AvatarMaterialStateShader.cginc".
    2) https://forums.oculus.com/developer/discussion/48199/avatar-surface-shader-errors#latest - was the second cause.
  • Rave185Rave185 Posts: 27
    Lawnmower Man (or Woman)
    Good news, my hard drive is back, apparently it was just a bugged windows install cause after I left it for a week it started again and restored my previous version of windows, everything's fine now! I'll start workin' on my project again soon @metrocube, thx!
  • onnevanonnevan Posts: 2
    Virtual Boy (or Girl)
    In 5.6 all objects are grey and grabbing don't work. Any chance to update the scripts?
2»
Sign In or Register to comment.