Skip to main content

ActorVisualController

The ActorVisualController manages the dynamic loading and customization of character visuals for players, handling modular equipment, skin tone, and animation via the Animancer system. It supports runtime addressable asset management and robust animation layering.


๐Ÿงฉ Overviewโ€‹

public class ActorVisualController : SerializedMonoBehaviour

A Unity MonoBehaviour component that assembles, animates, and tracks player avatars through addressable prefabs and modular components like PlayerItem_SO.


๐Ÿงฑ Visual Customizationโ€‹

SetAvatarItems(List<PlayerItem_SO> requestedItems, bool shouldSaveItems = true)โ€‹

  • Dynamically loads visual assets based on requested player items.
  • Handles merging with DefaultItems.
  • Clears or disables unused visuals based on the shouldDeleteUnusedItemsOnChange flag.
  • Loads the asset from SourcePrefab if necessary.

SetSkintone(PlayerSkintone newTone, bool shouldSave = false)โ€‹

  • Updates all PlayerSkintoneItem components to the specified tone.

PreviewOutfit(PlayerOutfit outfit)โ€‹

  • Swaps current visuals to reflect the passed outfit without saving changes permanently.

๐Ÿงฉ Animation API (Animancer-based)โ€‹

PlayClip(...), PlayMixer(...), etc.โ€‹

Animates the character using:

  • Single clips via ClipTransition.
  • Mixers like LinearMixerTransition or MixerTransition2D.
  • Controls layer weight, additive mode, masks, and time offset.

All play methods cache the active AnimationSequence per layer for state restoration and manipulation.

ApplyToAnimancers(int layer, float weight)โ€‹

  • Updates the weight of a specific animation layer.

FadeTo(int layer, FadeTo goal)โ€‹

  • Fades a layer fully in or out based on the FadeTo enum.

StopAnimancers(int layer) / StopAllAnimancers()โ€‹

  • Halts animations cleanly on one or all layers.

๐Ÿ”€ Visual Lifecycle & Asset Loadingโ€‹

LoadAsset()โ€‹

  • Loads the character prefab via Addressables and caches the result.

OnVisualsDespawned, OnVisualsSpawnedโ€‹

  • UnityEvents triggered on prefab replacement or initialization.

๐ŸŽฎ Runtime Attachmentsโ€‹

TrackedTransformsโ€‹

Tracks visual bones or sockets with NetworkTrackedTransforms for syncing purposes.

worldUI & moveUIToHeadโ€‹

UI element auto-repositions to the avatarโ€™s head using HeadTransformTracker.


๐Ÿ”„ Internal State & Cachingโ€‹

  • CurrentOutfit โ€“ currently displayed outfit.
  • _loadedAnimancer โ€“ reference to the AnimancerComponent on the visual prefab.
  • _activeLayerSequences โ€“ animation state info per layer.
  • _spawnedPrefab / _loadedPrefab โ€“ live and cached asset instances.
  • _loadedPlayerItems โ€“ cached PlayerItem components for visibility toggling.

๐Ÿง  Summaryโ€‹

ActorVisualController is the central avatar loader, animator, and manager in the m00m character system. It modularly assembles visual components based on player data, integrates animation layering, and supports real-time prefab lifecycle via Unity Addressables and Animancer.