UxrAvatar Class

Main class for avatars in the scene. An avatar is the visual representation of a user in the application. The minimal representation requires a single camera that allows the user to look around. More elements can be added such as hands to interact with the environment or a half/full body to have a more complete representation.

A special avatar is the local avatar, which is the avatar controlled by the user using the headset and input controllers. Non-local avatars are other avatars instantiated in the scene but not controlled by the user, either other users through the network or special cases such as automated replays. A quick way to access the local avatar is by using the UxrAvatar.LocalAvatar static property.

Although avatars may contain significant information and components, the avatar is not in charge of updating itself. Local avatars are updated by the UxrAvatarController added to the same GameObject where the UxrAvatar is. This allows to separate the update logic and functionality from the avatar representation. The standard avatar controller provided by UltimateXR is the UxrStandardAvatarController component. It provides high-level functionality to interact with the virtual world. Different update logic can be created by programming a new UxrAvatarController component if required.

Non-local avatars (Avatars whose UxrAvatar.AvatarMode is UpdateExternally) can be updated by accessing their rig using AvatarRig.

Local avatar update logic is handled automatically by the UxrManager singleton without requiring any user intervention.

Inheritance Hierarchy

System.Object
  Object
    Component
      Behaviour
        MonoBehaviour
          UltimateXR.Core.Components.UxrComponent
            UltimateXR.Core.Components.UxrComponent(UxrAvatar)
              UltimateXR.Avatar.UxrAvatar
Namespace: UltimateXR.Avatar
Assembly: UltimateXR (in UltimateXR.dll) Version: 0.0.0.0

Syntax

C#

[DisallowMultipleComponent]
public class UxrAvatar : UxrComponent<UxrAvatar>, 
	IUxrStateSync


The UxrAvatar type exposes the following members.

Constructors

NameDescription
Public methodUxrAvatar

Properties

NameDescription
Public propertyAllControllerInputs Gets all (enabled or disabled) controller inputs belonging to the avatar, except for any UxrDummyControllerInput component.
Public propertyAvatarController Gets the avatar controller, responsible for updating the avatar.
Public propertyAvatarMode Gets or sets the avatar operating mode.
Public propertyAvatarRenderers Gets the renderers used by the avatar, excluding controllers and everything related to them.
Public propertyAvatarRig Gets the avatar rig.
Public propertyAvatarRigInfo Gets the avatar rig information.
Public propertyAvatarRigType Gets the avatar rig type.
Public propertyCameraComponent Gets the avatar’s camera component.
Public propertyCameraController Gets the Transform of the camera controller (the parent transform of the avatar’s camera).
Public propertyCameraFade Gets the avatar’s camera fade component. If the camera doesn’t currently have one, it will be added.
Public propertyCameraFloorPosition Gets the avatar’s camera floor position: the camera position projected on the floor. This is useful when testing if the avatar is near a well known place or to trigger certain events.
Public propertyCameraForward Gets the avatar’s camera forward vector.
Public propertyCameraPosition Gets the avatar’s camera position.
Public propertyCameraTransform Gets the avatar’s camera transform.
Public propertyControllerInput Gets the first enabled controller input belonging to the avatar. If there is no enabled controller input available, to avoid null checks, it returns a dummy component that sends no input events.
Public propertyDefaultHandPose Gets or sets the default hand pose. The default hand pose is the pose a hand will have when no other event that changes the pose is happening. Usually it is a neutral, relaxed pose.
Public propertyDefaultHandPoseName Gets the default hand pose name or null if there isn’t any default hand pose set.
Public propertyEnabledControllerInputs Gets the currently enabled controller inputs belonging to the avatar, except for any UxrDummyControllerInput component.
Public propertyFingerTips Gets all the enabled UxrFingerTip components in the avatar.
Public propertyFirstControllerTracking Gets the first enabled tracking device that inherits from UxrControllerTracking, meaning a standard left+right controller setup.
Public propertyHasDummyControllerInput Gets whether the current controller input is a dummy controller input component. Dummy controller input is used when there is no VR input device available in order to avoid null checking.
Public propertyIsPrefabVariant Gets whether the avatar’s prefab has a parent avatar prefab.
Public propertyLaserPointers Gets all the enabled UxrLaserPointer components in the avatar.
Public propertyLeftGrabber Gets the left hand’s grabber component. Null if no left UxrGrabber component was found.
Public propertyLeftHand Gets the left hand.
Public propertyLeftHandBone Gets the left hand bone.
Public propertyStatic memberLocalAvatar Gets the local avatar or null if there is none.
Public propertyStatic memberLocalAvatarCamera Gets the camera component of the local avatar. If there is no local avatar it will return null.
Public propertyStatic memberLocalAvatarInput Gets the controller input of the local avatar. If there is a local avatar present, the controller input is guaranteed to be non-null. If there is no input available, the controller input will simply return a dummy object that will generate no input events. It will return null if there is no local avatar currently in the scene.
Public propertyStatic memberLocalStandardAvatarController Gets the standard avatar controller component if it exists.
Public propertyParentAvatarPrefab Gets the ParentPrefab’s UxrAvatar component.
Public propertyParentPrefab Gets the parent prefab GameObject, if it exists.
Public propertyPrefabGuid Gets the avatar prefab Guid. It is stored instead of the GameObject because storing the GameObject would make an instantiated avatar reference itself, instead of the source prefab.
Public propertyProjectedCameraForward Gets the avatar’s camera forward vector projected onto the XZ plane, the floor.
Public propertyRenderMode Gets or sets the avatar render mode.
Public propertyRightGrabber Gets the right hand’s grabber component. Null if no right UxrGrabber component was found.
Public propertyRightHand Gets the right hand.
Public propertyRightHandBone Gets the right hand bone.
Public propertyShowControllerHands Gets or sets whether the hands will be shown when the controllers are being rendered.
Public propertyTrackingDevices Returns all available enabled tracking devices.

Methods

NameDescription
Protected methodAwake Initializes the avatar. (Overrides UxrComponent<T>.Awake().)
Public methodClearRigElements Clears all the AvatarRig element references.
Public methodEnableFingerTips Enables or disables the UxrFingerTip components in the avatar.
Public methodEnableLaserPointers Enables or disables the UxrLaserPointer components in the avatar.
Public methodEnableLocomotion Enables or disables the UxrLocomotion components in the avatar.
Public methodGetAllAvatarRendererComponents Gets all Renderer components except those hanging from a UxrHandIntegration object, which are renderers that are not part of the avatar itself but part of the supported input controllers / controller hands that can be rendered too.
Public methodGetAllHandPoses Gets all hand poses in the avatar, including those inherited from parent prefabs. If more than one pose exists with the same name, only the overriden will be in the results.
Public methodGetArm Gets the UxrAvatarArm rig information for the given arm.
Public methodGetAvatarChain Gets the UxrAvatar component chain. This is the avatar’s own UxrAvatar component followed by all parent prefab UxrAvatar components up to the root parent prefab. If the avatar is an instance the first component will reference its own component instantiated in the scene, not the avatar component in the source prefab. GetPrefabGuidChain() can be used to traverse the prefab chain information including the source prefab.
Public methodGetControllerInputForward Gets the transform in the given hand controller that points forward. The controller needs to have a 3D model assigned to it, which all controllers in the framework have.
Public methodGetCurrentRuntimeHandPose Gets the current runtime hand pose.
Public methodGetGrabber Gets the UxrGrabber component for the given hand.
Public methodGetHand Gets the UxrAvatarHand rig information for the given hand.
Public methodGetHandBone Gets the given hand bone.
Public methodGetHandPose Gets a given hand pose. It can happen that the pose name is present in a prefab/instance and at the same time also in any of the parent prefabs upwards in the hierarchy. In this case the hand pose in the child will always have priority so that child prefabs can override poses that they inherit from parent prefabs.
Public methodGetHandPoses Gets the hand poses in the avatar, not counting those inherited from parent prefabs.
Public methodGetInitialBoneLocalPosition Gets the initial local position of the given avatar bone.
Public methodGetInitialBoneLocalRotation Gets the initial local rotation of the given avatar bone.
Public methodGetParentPrefab(String) Gets the parent prefab that stores a given hand pose.
Public methodGetParentPrefab(UxrHandPoseAsset) Gets the parent prefab that stores a given hand pose.
Public methodGetParentPrefabChain Gets the parent prefab chain. These are all parent prefabs up to the root parent prefab.
Public methodGetPrefabGuidChain Gets the prefab GUID chain. This is the source prefab Guid followed by all parent prefab GUIDs up to the root parent prefab.
Public methodGetRuntimeHandPose Gets a given hand pose. This method is intended for use at runtime to animate the avatars. While GetHandPose(String, Boolean) uses UxrHandPoseAsset, GetRuntimeHandPose(String) uses UxrRuntimeHandPose. The main differences are:  
  • UxrRuntimeHandPose objects contain transforms that require less operations and are valid only for this avatar. They are high-performant and cached at the beginning, making them only available at runtime. They are used to animate the avatar hands at runtime.
  • UxrHandPoseAsset objects contain transforms that are independent of the coordinate system used. They require more operations but can be applied to any avatar. They are mainly used in editor mode.
Public methodIsHandPoseOverriden(UxrHandPoseAsset) Checks if a given pose has been overriden in the prefab hierarchy.
Public methodIsHandPoseOverriden(String, UxrAvatar) Checks if a given pose has been overriden in any point in the prefab hierarchy.
Public methodIsLookingAt Checks if the avatar is looking at a point in space.
Public methodIsPrefabCompatibleWith Checks whether the avatar shares the same prefab or is a prefab variant of another avatar.
Protected methodOnHandPoseChanged Event trigger for the HandPoseChanged and [!:GlobalHandPoseChanged] events.
Protected methodOnHandPoseChanging Event trigger for the HandPoseChanging and [!:GlobalHandPoseChanging] events.
Protected methodOnValidate Called when inspector fields are changed. It is used to regenerate the rig information. (Overrides UxrComponent.OnValidate().)
Protected methodReset Makes sure the rig constructor is called when the component is reset. (Overrides UxrComponent.Reset().)
Public methodSetCameraAtFloorLevel Places the camera at floor level.
Public methodSetCurrentHandPose Sets the currently active pose for a given hand in the avatar at runtime. Blending is used to transition between poses smoothly, which means the pose is not immediately adopted. To adopt a pose immediately at a given instant use SetCurrentHandPoseImmediately(UxrHandSide, String, UxrBlendPoseType) instead.
Public methodSetCurrentHandPoseBlendValue Sets the currently active pose blend value, if the current pose is Blend.
Public methodSetCurrentHandPoseImmediately(UxrHandSide, String, UxrBlendPoseType) Adopts a given hand pose by changing the transforms immediately. The bones may be overriden at any other point or the next frame if there is a hand pose currently enabled using SetCurrentHandPose(UxrHandSide, String, Single, Boolean).
Public methodSetCurrentHandPoseImmediately(UxrHandSide, UxrHandPoseAsset, UxrBlendPoseType) Adopts a given hand pose by changing the transforms immediately. The bones may be overriden at any other point or the next frame if there is a hand pose currently enabled using SetCurrentHandPose(UxrHandSide, String, Single, Boolean).
Public methodSetupRigElementsFromAnimator Sets up the AvatarRig using information from the Animator if it describes a humanoid avatar.
Protected methodStart Additional avatar initialization. (Overrides UxrComponent.Start().)
Public methodSyncState Executes the state change described by [!:e].
Public methodTryToInferMissingRigElements Tries to infer rig elements by doing some checks on names and bone hierarchy. This is useful when we have a rig that has no full humanoid avatar set up on its animator .

Events

NameDescription
Public eventAvatarUpdated Event called right after the avatar goes through an UxrUpdateStage of the updating process.
Public eventAvatarUpdating Event called right before before the avatar goes through an UxrUpdateStage of the updating process.
Public eventHandPoseChanged Event called right after the avatar changed a hand’s pose.
Public eventHandPoseChanging Event called right before the avatar is about to change a hand’s pose.
Public eventStatic memberLocalAvatarStarted Event called right after after the local avatar called its Start(). This is useful when the avatar is instantiated in a deferred way, such as a networking environment, and the avatar isn’t ready during Awake()/OnEnable()/Start().
Public eventStateChanged Event raised when a relevant state of an object changed and requires storage/synchronization.

Extension Methods

NameDescription
Public Extension MethodCheckSetEnabled Enables/disabled the component if it isn’t enabled already. (Defined by MonoBehaviourExt.)
Public Extension MethodGetOrAddComponent<T> Gets the Component of a given type. If it doesn’t exist, it is added to the GameObject. (Defined by ComponentExt.)
Public Extension MethodGetPathUnderScene Gets the full path under current scene, including all parents, but scene name, for the given component. (Defined by ComponentExt.)
Public Extension MethodGetSceneUid Gets an unique identifier string for the given component. (Defined by ComponentExt.)
Public Extension MethodGetUniqueScenePath Gets an unique path in the scene for the given component. It will include scene name, sibling and component indices to make it unique. (Defined by ComponentExt.)
Public Extension MethodLoopCoroutine Creates a coroutine that simplifies executing a loop during a certain amount of time. (Defined by MonoBehaviourExt.)
Public Extension MethodSafeGetComponentInParent<T> Gets the Component of a given type in the GameObject or any of its parents. It also works on prefabs, where regular GetComponentInParent(Type, Boolean) will not work: https://issuetracker.unity3d.com/issues/getcomponentinparent-is-returning-null-when-the-gameobject-is-a-prefab (Defined by ComponentExt.)
Public Extension MethodShowInInspector(Boolean)Overloaded.
Controls whether to show the current object in the inspector. (Defined by ObjectExt.)
Public Extension MethodShowInInspector(Boolean, Boolean)Overloaded.
Controls whether to show the current object in the inspector and whether it is editable. (Defined by ObjectExt.)
Public Extension MethodThrowIfNull Throws an exception if the object is null. (Defined by ObjectExt.)

See Also

Reference

UltimateXR.Avatar Namespace