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?
Original Post on Discord
by user 103054507105067008
I’ll be sure to share an example of what I figure out with this if anyone else is interested in doing the same
by user 103054507105067008
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.
by user 395602247196737546
No - they’re generated when you request quicklook (the usdz) 
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?
by user 103054507105067008
What do you mean you cant set them?
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?

by user 103054507105067008
Trying to set them here
by user 103054507105067008
You can’t make an assignment with an implicit check for undefined.
You have to write it like this:
if(buttonClickComp && this.new) buttonClickComp.target = this.new.transform;
That’s not related to everywhere actions but javascript syntax
Sweet thanks, sometimes I headbutt stuff like that coming back from C# to Javascript
by user 103054507105067008
You’re right, I’m being slow today lol
by user 103054507105067008
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?
by user 103054507105067008
Or any way to create an Animator component then add the animations to it at runtime?
by user 103054507105067008
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
by user 103054507105067008