I am looking into dynamically adding buttons to play animations if a model has animations when imported using Everywhere actions for Quick Look/Android WebXR on an existing model viewer I have made which imports a model at runtime.
In this example I import a model, if it has animations then I create some everywhere actions components and spawn buttons hooked up to those at runtime which play the animations on the model when opened in Quick Look/WebXR. Is this possible currently?
interesting. so pressing quick look creates a usdz file on the fly including the actions? i was under the impression they were “baked” during export.
We automatically generate the usdz behaviours for everywhere action components (you can look at their source for how to do it) but you can also do it for your own components (these are our methods for building them: Everywhere Actions | Needle Engine Documentation)
I think I need to figure out how to build my own at runtime as I can’t set these values like target etc on an existing prefab or instantiated button with the PlayAnimationOnClick component?
The fields are not used/cached anywhere else before the events for click or export happen. Setting them should work. Are you sure you assign correct values?
I can very easily create an Animation component at runtime and add the animations to it to trigger, but the PlayAnimationOnClick script uses an Animator instead which doesn’t seem to be as straightforward for me to create at runtime, is there some way to convert an Animation component into an Animator component at runtime?
Currently that’s not as straightforward because of the AnimatorStateMachine which is a bit more complex (just from the data that needs to be setup) - you can create the statemachine from code too tho (have a look at the model field inside the AnimatorController class - that’s what you need to create and assing from code
Trying to figure out where to start there, thanks for the tip - I wonder if I am going about this the right way or if there is a way to do this with the Animation component otherwise