The handle of the Unity component attached to an object.

This handle can be obtained by following APIs.

If the instance is obtained by ClusterScript.getUnityComponent or SubNode.getUnityComponent, the operations to the handle will change the appearance and behavior of the item. The change can be seen by any players.

If the instance is obtained by PlayerLocalObject.getUnityComponent, the operation to the handle will change the appearance and behavior of the item, which can be seen only by the player.

There APIs supports same list of component names. Below is the list of available type names forgetUnityComponent method.

  • "Animator"
  • "AudioSource"
  • "Button"
  • "Camera"
  • "Canvas"
  • "CanvasGroup"
  • "BoxCollider"
  • "CapsuleCollider"
  • "GridLayoutGroup"
  • "HorizontalLayoutGroup"
  • "Image"
  • "MeshCollider"
  • "MeshRenderer"
  • "ParticleSystem"
  • "PlayableDirector"
  • "PositionConstraint"
  • "PostProcessVolume"
  • "RawImage"
  • "RectTransform"
  • "Rigidbody"
  • "RotationConstraint"
  • "ScaleConstraint"
  • "SkinnedMeshRenderer"
  • "SphereCollider"
  • "Text"
  • "Transform"
  • "VerticalLayoutGroup"
  • "VideoPlayer"

Hierarchy

  • UnityComponent

Properties

unityProp: UnityComponentPropertyProxy

The handle to access the property of the Unity component.

This API requires the exact name of the property of the Unity component. The name of the property shown in the Unity Editor may be different from the actual property name. Please refer to the Unity API reference for details.

The properties that can be accessed with unityProp must be one of the following data types: bool, int, float, double, string, Vector2, Vector3, Vector4, Quaternion, Color, or a derived type of Enum.

If you try to access a property of a different data type, null will be returned when getting the property, and an exception will be thrown when setting the property.

Vector4 is represented as a float array of length 4, with elements corresponding to x, y, z, and w. When you get a property of type Vector4, a float array of length 4 is returned. Similarly, when setting a property of type Vector4, specify a float array of length 4.

Color is represented as a float array of length 4, with elements corresponding to r, g, b, and a. When you get a property of type Color, a float array of length 4 is returned. Similarly, when setting a property of type Color, specify a float array of length 4.

Enum is represented as an int value. Similarly, when setting a property of type Enum, specify an int value. Please refer to the Unity API reference to see the correspondence between the value of Enum and the internal int value.

In Player Script, the properties updated by this method are only reflected in the player running the script.

In Scriptable Item, the value of the property specified by this method is synchronized over the network. Please be aware it may not be reflected immediately, and no interpolation is applied to the value.

Example

// An example for Scriptable Item to set the property of the component in SubNode
let node = $.subNode("Cube");
let meshRenderer = node.getUnityComponent("MeshRenderer");
meshRenderer.unityProp.receiveShadows = false;

let transform = node.getUnityComponent("Transform");
transform.unityProp.localScale = new Vector3(2, 2, 2);

Example

// An example for Player Script to set the property of the component in PlayerLocalObject
let imageObject = _.playerLocalObject("ImageObject");
let image = imageObject.getUnityComponent("Image");
image.unityProp.color = [1, 0, 0, 1];

let textObject = _.playerLocalObject("TextObject");
let textComponent = textObject.getUnityComponent("Text");
textComponent.unityProp.text = "Hello, World!";

In Scriptable Item, This API will result in undefined behavior if the same property is updated by this API and other methods. When this API and Animator etc. update the same property, the behavior is undefined. Also, other APIs such as SubNode.setPosition that update Transform.localPosition internally, will result in undefined behavior when used in combination with this API to update Transform.localPosition.

To avoid undefined behavior, consider the following when using Scriptable Item:

  • When using this API, do not control the same property with other components (Animator etc.).
  • Try to use other existing APIs to control the object, if it enough matches the purpose.

For example, consider using ClusterScript.setPosition to change the position of an item, instead of using this API to update Transform.localPosition.

In Scriptable Item, the available properties with this API are limited to make the properties synchronized between players. The available properties are enabled and following properties for each types.

  • AudioSource
    • bypassEffects
    • bypassListenerEffects
    • bypassReverbZones
    • dopplerLevel
    • loop
    • maxDistance
    • minDistance
    • mute
    • panStereo
    • pitch
    • playOnAwake
    • priority
    • spatialize
    • spatializePostEffects
  • BoxCollider
    • center
    • isTrigger
    • size
  • Button
    • interactable
    • transition
  • Camera
    • allowMSAA
    • backgroundColor
    • depth
    • farClipPlane
    • fieldOfView
    • focalLength
    • forceIntoRenderTexture
    • allowHDR
    • lensShift
    • nearClipPlane
    • useOcclusionCulling
    • orthographic
    • orthographicSize
    • stereoConvergence
    • stereoSeparation
  • Canvas
    • overridePixelPerfect
    • overrideSorting
    • pixelPerfect
    • planeDistance
    • normalizedSortingGridSize
  • CanvasGroup
    • alpha
    • blocksRaycasts
    • ignoreParentGroups
    • interactable
  • CapsuleCollider
    • center
    • height
    • isTrigger
    • radius
  • GridLayoutGroup
    • cellSize
    • childAlignment
    • constraint
    • constraintCount
    • spacing
    • startAxis
    • startCorner
  • HorizontalLayoutGroup
    • childAlignment
    • childControlHeight
    • childControlWidth
    • childForceExpandHeight
    • childForceExpandWidth
    • childScaleHeight
    • childScaleWidth
    • reverseArrangement
    • spacing
  • Image
    • color
    • fillAmount
    • fillCenter
    • fillClockwise
    • fillMethod
    • fillOrigin
    • maskable
    • pixelsPerUnitMultiplier
    • preserveAspect
    • raycastPadding
    • raycastTarget
    • type
    • useSpriteMesh
  • MeshCollider
    • convex
    • isTrigger
  • MeshRenderer
    • receiveShadows
    • rendererPriority
    • sortingOrder
  • PositionConstraint
    • constraintActive
    • translationAxis
    • translationAtRest
    • translationOffset
    • weight
  • PostProcessVolume
    • blendDistance
    • isGlobal
    • priority
    • weight
  • RawImage
    • color
    • maskable
    • raycastPadding
    • raycastTarget
  • RectTransform
    • anchorMax
    • anchorMin
    • anchoredPosition
    • pivot
    • localPosition
    • localScale
    • sizeDelta
  • Rigidbody
    • angularDrag
    • drag
    • isKinematic
    • mass
    • useGravity
  • RotationConstraint
    • constraintActive
    • rotationAxis
    • rotationAtRest
    • rotationOffset
    • weight
  • ScaleConstraint
    • constraintActive
    • scalingAxis
    • scaleAtRest
    • scaleOffset
    • weight
  • SkinnedMeshRenderer
    • receiveShadows
    • rendererPriority
    • skinnedMotionVectors
    • sortingOrder
    • updateWhenOffscreen
  • SphereCollider
    • center
    • isTrigger
    • radius
  • Text
    • text
    • color
    • maskable
    • raycastPadding
    • raycastTarget
  • Transform
    • localPosition
    • localRotation
    • localScale
  • VerticalLayoutGroup
    • childAlignment
    • childControlHeight
    • childControlWidth
    • childForceExpandHeight
    • childForceExpandWidth
    • childScaleHeight
    • childScaleWidth
    • reverseArrangement
    • spacing
  • VideoPlayer
    • sendFrameReadyEvents
    • isLooping
    • playOnAwake
    • playbackSpeed
    • skipOnDrop
    • targetCameraAlpha
    • waitForFirstFrame

Methods

  • Beta

    Plays the component if the handled component is PlayableDirector, AudioSource, ParticleSystem, or VideoPlayer.

    An error will occur for other components.

    If the instance is obtained by ClusterScript.getUnityComponent by SubNode.getUnityComponent and the handled component is PlayableDirector, AudioSource, its time will look same for all players. The beginning of the playback may be skipped.

    When play() is called for already playing component, the component will stop and restart playing.

    For ParticleSystem, this method also plays particles attached in children objects. If both a parent and child object have ParticleSystem, please execute play() or stop() on the particles of the parent only. If play() or stop() is called for multiple ParticleSystems in a parent-child relationship, they may not play correctly.

    For VideoPlayer, it is recommended to specify Video Clip for Source and Material Override for Render Mode. If Source is set to Video Clip, the playback time will look same for all players. The beginning of the playback may be skipped. Also, depending on the size of the video and the encoding method, it may take some time for playback to start.

    If Source is URL, there will be a large delay until the playback actually starts. Also, the playback start timing and playback time will not be consistent for each player.

    If the rendering result of VideoPlayer is applied to Render Texture, the rendering state when not playing will change depending on the OS and texture settings. Consider to hide the texture when VideoPlayer is not playing.

    Returns void

  • Beta

    Sets Bool parameter value of the AnimatorController, if the handled component is Animator. An error will occur for other components.

    This method does nothing if the parameter does not exist, or if it is not Bool.

    Parameters

    • id: string

      Name of the parameter

    • value: boolean

      The value to set

    Returns void

  • Beta

    Sets Float parameter value of the AnimatorController, if the handled component is Animator. An error will occur for other components.

    This method does nothing if the parameter does not exist, or if it is not Float.

    Parameters

    • id: string

      Name of the parameter

    • value: number

      The value to set

    Returns void

  • Beta

    Sets Integer parameter value of the AnimatorController, if the handled component is Animator. An error will occur for other components.

    This method does nothing if the parameter does not exist, or if it is not Integer.

    Parameters

    • id: string

      Name of the parameter

    • value: number

      The value to set

    Returns void

  • Beta

    Sets Trigger of the AnimatorController, if the handled component is Animator. An error will occur for other components.

    This method does nothing if the parameter does not exist, or if it is not Trigger.

    Parameters

    • id: string

      The name of the parameter

    Returns void

  • Beta

    Stops the component playback if the handled component is PlayableDirector, AudioSource, ParticleSystem, or VideoPlayer.

    An error will occur for other components.

    Playback time will be reset when stop() is called for PlayableDirector and VideoPlayer.

    For ParticleSystem, this method also stops particles attached in children objects. If both a parent and child object have ParticleSystem, please execute play() or stop() on the particles of the parent only. If play() or stop() is called for multiple ParticleSystems in a parent-child relationship, they may not play correctly.

    Returns void

Generated using TypeDoc