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
Name | Description | |
---|---|---|
UxrAvatar |
Properties
Name | Description | |
---|---|---|
AllControllerInputs | Gets all (enabled or disabled) controller inputs belonging to the avatar, except for any UxrDummyControllerInput component. | |
AvatarController | Gets the avatar controller, responsible for updating the avatar. | |
AvatarMode | Gets or sets the avatar operating mode. | |
AvatarRenderers | Gets the renderers used by the avatar, excluding controllers and everything related to them. | |
AvatarRig | Gets the avatar rig. | |
AvatarRigInfo | Gets the avatar rig information. | |
AvatarRigType | Gets the avatar rig type. | |
CameraComponent | Gets the avatar’s camera component. | |
CameraController | Gets the Transform of the camera controller (the parent transform of the avatar’s camera). | |
CameraFade | Gets the avatar’s camera fade component. If the camera doesn’t currently have one, it will be added. | |
CameraFloorPosition | 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. | |
CameraForward | Gets the avatar’s camera forward vector. | |
CameraPosition | Gets the avatar’s camera position. | |
CameraTransform | Gets the avatar’s camera transform. | |
ControllerInput | 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. | |
DefaultHandPose | 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. | |
DefaultHandPoseName | Gets the default hand pose name or null if there isn’t any default hand pose set. | |
EnabledControllerInputs | Gets the currently enabled controller inputs belonging to the avatar, except for any UxrDummyControllerInput component. | |
FingerTips | Gets all the enabled UxrFingerTip components in the avatar. | |
FirstControllerTracking | Gets the first enabled tracking device that inherits from UxrControllerTracking, meaning a standard left+right controller setup. | |
HasDummyControllerInput | 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. | |
IsPrefabVariant | Gets whether the avatar’s prefab has a parent avatar prefab. | |
LaserPointers | Gets all the enabled UxrLaserPointer components in the avatar. | |
LeftGrabber | Gets the left hand’s grabber component. Null if no left UxrGrabber component was found. | |
LeftHand | Gets the left hand. | |
LeftHandBone | Gets the left hand bone. | |
LocalAvatar | Gets the local avatar or null if there is none. | |
LocalAvatarCamera | Gets the camera component of the local avatar. If there is no local avatar it will return null. | |
LocalAvatarInput | 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. | |
LocalStandardAvatarController | Gets the standard avatar controller component if it exists. | |
ParentAvatarPrefab | Gets the ParentPrefab’s UxrAvatar component. | |
ParentPrefab | Gets the parent prefab GameObject, if it exists. | |
PrefabGuid | 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. | |
ProjectedCameraForward | Gets the avatar’s camera forward vector projected onto the XZ plane, the floor. | |
RenderMode | Gets or sets the avatar render mode. | |
RightGrabber | Gets the right hand’s grabber component. Null if no right UxrGrabber component was found. | |
RightHand | Gets the right hand. | |
RightHandBone | Gets the right hand bone. | |
ShowControllerHands | Gets or sets whether the hands will be shown when the controllers are being rendered. | |
TrackingDevices | Returns all available enabled tracking devices. |
Methods
Name | Description | |
---|---|---|
Awake | Initializes the avatar. (Overrides UxrComponent<T>.Awake().) | |
ClearRigElements | Clears all the AvatarRig element references. | |
EnableFingerTips | Enables or disables the UxrFingerTip components in the avatar. | |
EnableLaserPointers | Enables or disables the UxrLaserPointer components in the avatar. | |
EnableLocomotion | Enables or disables the UxrLocomotion components in the avatar. | |
GetAllAvatarRendererComponents | 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. | |
GetAllHandPoses | 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. | |
GetArm | Gets the UxrAvatarArm rig information for the given arm. | |
GetAvatarChain | 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. | |
GetControllerInputForward | 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. | |
GetCurrentRuntimeHandPose | Gets the current runtime hand pose. | |
GetGrabber | Gets the UxrGrabber component for the given hand. | |
GetHand | Gets the UxrAvatarHand rig information for the given hand. | |
GetHandBone | Gets the given hand bone. | |
GetHandPose | 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. | |
GetHandPoses | Gets the hand poses in the avatar, not counting those inherited from parent prefabs. | |
GetInitialBoneLocalPosition | Gets the initial local position of the given avatar bone. | |
GetInitialBoneLocalRotation | Gets the initial local rotation of the given avatar bone. | |
GetParentPrefab(String) | Gets the parent prefab that stores a given hand pose. | |
GetParentPrefab(UxrHandPoseAsset) | Gets the parent prefab that stores a given hand pose. | |
GetParentPrefabChain | Gets the parent prefab chain. These are all parent prefabs up to the root parent prefab. | |
GetPrefabGuidChain | Gets the prefab GUID chain. This is the source prefab Guid followed by all parent prefab GUIDs up to the root parent prefab. | |
GetRuntimeHandPose |
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:
| |
IsHandPoseOverriden(UxrHandPoseAsset) | Checks if a given pose has been overriden in the prefab hierarchy. | |
IsHandPoseOverriden(String, UxrAvatar) | Checks if a given pose has been overriden in any point in the prefab hierarchy. | |
IsLookingAt | Checks if the avatar is looking at a point in space. | |
IsPrefabCompatibleWith | Checks whether the avatar shares the same prefab or is a prefab variant of another avatar. | |
OnHandPoseChanged | Event trigger for the HandPoseChanged and [!:GlobalHandPoseChanged] events. | |
OnHandPoseChanging | Event trigger for the HandPoseChanging and [!:GlobalHandPoseChanging] events. | |
OnValidate | Called when inspector fields are changed. It is used to regenerate the rig information. (Overrides UxrComponent.OnValidate().) | |
Reset | Makes sure the rig constructor is called when the component is reset. (Overrides UxrComponent.Reset().) | |
SetCameraAtFloorLevel | Places the camera at floor level. | |
SetCurrentHandPose | 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. | |
SetCurrentHandPoseBlendValue | Sets the currently active pose blend value, if the current pose is Blend. | |
SetCurrentHandPoseImmediately(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). | |
SetCurrentHandPoseImmediately(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). | |
SetupRigElementsFromAnimator | Sets up the AvatarRig using information from the Animator if it describes a humanoid avatar. | |
Start | Additional avatar initialization. (Overrides UxrComponent.Start().) | |
SyncState | Executes the state change described by [!:e]. | |
TryToInferMissingRigElements | 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
Name | Description | |
---|---|---|
AvatarUpdated | Event called right after the avatar goes through an UxrUpdateStage of the updating process. | |
AvatarUpdating | Event called right before before the avatar goes through an UxrUpdateStage of the updating process. | |
HandPoseChanged | Event called right after the avatar changed a hand’s pose. | |
HandPoseChanging | Event called right before the avatar is about to change a hand’s pose. | |
LocalAvatarStarted | 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(). | |
StateChanged | Event raised when a relevant state of an object changed and requires storage/synchronization. |
Extension Methods
Name | Description | |
---|---|---|
CheckSetEnabled | Enables/disabled the component if it isn’t enabled already. (Defined by MonoBehaviourExt.) | |
GetOrAddComponent<T> | Gets the Component of a given type. If it doesn’t exist, it is added to the GameObject. (Defined by ComponentExt.) | |
GetPathUnderScene | Gets the full path under current scene, including all parents, but scene name, for the given component. (Defined by ComponentExt.) | |
GetSceneUid | Gets an unique identifier string for the given component. (Defined by ComponentExt.) | |
GetUniqueScenePath | 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.) | |
LoopCoroutine | Creates a coroutine that simplifies executing a loop during a certain amount of time. (Defined by MonoBehaviourExt.) | |
SafeGetComponentInParent<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.) | |
ShowInInspector(Boolean) | Overloaded. Controls whether to show the current object in the inspector. (Defined by ObjectExt.) | |
ShowInInspector(Boolean, Boolean) | Overloaded. Controls whether to show the current object in the inspector and whether it is editable. (Defined by ObjectExt.) | |
ThrowIfNull | Throws an exception if the object is null. (Defined by ObjectExt.) |