cancel
Showing results for 
Search instead for 
Did you mean: 

[Integration Notice] Avatar Grab Unity sample available

mfmf
Oculus Staff
Hey folks: we've put together a sample of using the Avatar SDK with a few scripts to add object grab/throw functionality. I've attached it here. It requires the Oculus Utilities for Unity, and the Avatar SDK. 

This isn't the end of our hand samples, but I didn't want to leave you without at least a basic grab sample for too long. 

Known issue: it works in 5.5.0f3, but crashes in all 5.4.x versions of Unity I've tested so far. For now it's a 5.5-only sample. It doesn't rely on any 5.5-only functionality, however, so you should be able to use the scripts in 5.4 without a problem.

EDIT: updated to behave well with locomotion such as OVRPlayerController, 1/3/2017.
53 REPLIES 53

StormyDoesVR
Heroic Explorer

pjenness said:


Rave185 said:

@pjenness

Thanks for the code sample! Just having a bit of trouble, it doesn't recognize the word User and continues to error out. Any idea why that could be happening?


HIya

Do you have this at the start of your script file?

using Oculus.Platform.Models;


-P



Hmm... it says the namespace platform does not exist. Am I missing a package or something? Thx!
------------------------------
PC specs - GTX 1070 (MSI AERO); 16GB Corsair Vengeance DDR3; intel i5-4590, MSI motherboard (don't remember but it was a combo deal) and an EVGA Supernova 750W semi-modular.

StormyDoesVR
Heroic Explorer

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! ^^
------------------------------
PC specs - GTX 1070 (MSI AERO); 16GB Corsair Vengeance DDR3; intel i5-4590, MSI motherboard (don't remember but it was a combo deal) and an EVGA Supernova 750W semi-modular.

StormyDoesVR
Heroic Explorer
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!
------------------------------
PC specs - GTX 1070 (MSI AERO); 16GB Corsair Vengeance DDR3; intel i5-4590, MSI motherboard (don't remember but it was a combo deal) and an EVGA Supernova 750W semi-modular.

StormyDoesVR
Heroic Explorer
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)
------------------------------
PC specs - GTX 1070 (MSI AERO); 16GB Corsair Vengeance DDR3; intel i5-4590, MSI motherboard (don't remember but it was a combo deal) and an EVGA Supernova 750W semi-modular.

pjenness
Rising Star
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

StormyDoesVR
Heroic Explorer
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!
------------------------------
PC specs - GTX 1070 (MSI AERO); 16GB Corsair Vengeance DDR3; intel i5-4590, MSI motherboard (don't remember but it was a combo deal) and an EVGA Supernova 750W semi-modular.

pjenness
Rising Star
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

StormyDoesVR
Heroic Explorer
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. ^^
------------------------------
PC specs - GTX 1070 (MSI AERO); 16GB Corsair Vengeance DDR3; intel i5-4590, MSI motherboard (don't remember but it was a combo deal) and an EVGA Supernova 750W semi-modular.

Anonymous
Not applicable
@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.

StormyDoesVR
Heroic Explorer
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. 
------------------------------
PC specs - GTX 1070 (MSI AERO); 16GB Corsair Vengeance DDR3; intel i5-4590, MSI motherboard (don't remember but it was a combo deal) and an EVGA Supernova 750W semi-modular.