KybernetikGames / animancer

Documentation for the Animancer Unity Plugin.
63 stars 8 forks source link

Set Binding from code. #320

Closed abdouhe7 closed 8 months ago

abdouhe7 commented 9 months ago

Environment

Animancer Version Number: 7.4.2 Animancer Pro or Lite: Pro Unity Version: Unity 2022.3.6 Platform: Windows

Description

Hello. I'm trying to activate the animancer component on the runtime. so I swap the playableasset - . Transition asset.

And it contain a timeline unity asset. So. It gives in a unity inspector then. name and. the field of the binding ref. image

1- how exactly Can I know the name of the binding? as it's shown on the inspector, not the name of the reference object itself, because when I write : log(PlayableAnimancer.Bindings[0].name); It gives a null reference because of the name of the reference object itself.

2- And How exactly can I set this in the code ? to be like this for Example

foreach (Object binding in PlayableAnimancer.Bindings)
                {
                    if (binding as Animator)
                    {
                        if (binding.name == MyName)
                        {
                            Animator test = GameManger.GetComponent<Animator>();

                            binding = test as Object;

                        }
                    }
                }
KybernetikGames commented 8 months ago

Take a look at the PlayableAssetState.InitializeBindings method. Basically, it goes through the timelineAsset.outputs and calls GetBindingDetails for each of them to get their type and name, which lines up with the indices in the transition.Bindings array.

abdouhe7 commented 8 months ago

Thanks, I use that to create my own logic.