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
shouldDeleteUnusedItemsOnChangeflag. - Loads the asset from
SourcePrefabif necessary.
SetSkintone(PlayerSkintone newTone, bool shouldSave = false)โ
- Updates all
PlayerSkintoneItemcomponents 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
LinearMixerTransitionorMixerTransition2D. - 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
FadeToenum.
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.