Hiā¦ so, Iām not sure that the following is particularly Needle and/or Unity-related but Iām hoping someone might be able to help.
Basically, I have a .glb which has a looping animation set to āPlay Automaticallyā using the animation component. This works perfectly and the animation plays exactly as expected.
I also have an audio track which needs to accompany the animation and run/loop in sync with it. However, of course even with āPlay On Awakeā checked in the āAudio Sourceā component the track wonāt begin playing until there has been some user interaction (i.e. rotating the view of the scene or similar.)ā¦ by which time itās out of sync with the animation which has already been running.
I know that the āuser interaction to start audioā thing has always existedā¦ with all web contentā¦ since the dawn of time ā¦ but Iām trying to ascertain what might be the best solution in this instance? I donāt necessarily need the animation to start right away, so perhaps, instead of it playing automatically, thereās a way to set the animation to only begin playing on user interaction, in the same way as the audio so they run in sync with each other?
Or maybe thereās a better way to achieve what Iām aiming for?
so usually this is solved by having some sort of āPlayā button front and center, and when someone clicks that both audio and animation play in sync
For actually playing in sync and not deviating: usually you check the time offset between audio and animation and decide which one should be corrected if the time offset becomes bigger than, say, 0.1s
We do this internally for Timeline tracks - so if you just add your animation and audio to a Timeline in Unity that will be taken care of already
You could have a look at the scrollytelling scene from our samples to see a simple reference (or import the timeline samples from unityās timeline package via the package manager window)
Given that, at the moment, the audio begins playing when a user interacts with the content without me having to add a start button or any extra controllers or timelines anything, is there a reason why I canāt āattachā my animation to whatever is making that happen?
i.e. thereās obviously some sort of āstart on user interactionā thing in already existence, so might it be possible to somehow āpiggy-backā on that rather than introduce additional stuff? Or perhaps that aspect of things isnāt related to Unity or Needle?
You could of course hook into e.g. the AudioSource.audio (which is the threejs SpatialAudio class i think) and use the events to start and update your animation manually too and try to keep it in sync
You can totally do that! E.g. there could be a character with an idle animation waving at you, and once you do anything (click, drag, interact) another animation + synced audio plays
Okay, so despite several days (and nights) wrestling with this Iām really not getting anywhere with my hoped-for outcome.
THE DISCLAIMER
It should be noted that the failings Iām experiencing are down to my own ineptitude, not Unity or Needle problems.
**THE UPS & DOWNS **
Iāve successfully created a PlayableDirector with an associated timeline asset - and when I set it to āPlay On Awakeā the timeline runs as anticipated. So far, so good
However, what I need it to do (and what Iām singularly failing to achieve) is for it to only begin playing on user interaction.
Iāve unchecked āPlay On Awakeā in the PlayableDirector (which successfully stops the timeline from playing automatically) but have been unable to find a way to make it start playing when required
As mentioned previously, in an ideal world what Iād really like is for the timeline to be triggered to play as soon as the user begins exploring the scene (via the orbit controls, for example).
However, I havenāt had any luck trying to find general info about how to go about achieving that. So, instead, Iāve tried to trigger it via a buttonā¦ but Iām obviously doing something terribly wrong as none of the various, and undoubtedly messy, permutations that Iāve concocted make it run
THE PLEA FOR HELP
So, basically Iām trying to find a simple, straightforward walkthrough (if one exists) describing how to make either of the following happen:-
1). The PlayableDirector with its associated timeline starts playing as soon as thereās a user interaction (preferred).
2). The PlayableDirector with its associated timeline starts playing as soon as a button is clicked (happy to go with that if option 1 isnāt viable).
THE SCRUTINY OF MY VERY SOUL
I have a horrible sinking feeling that all my troubles and woes can be placed firmly in the āI donāt know anything about Unityā category. A problem compounded by the fact that I find Unity seems to insist on even the simplest of tasks being an exercise in labyrinthine torture; something which has made me reluctant to pursue it much in the past.
ISNāT THERE ANYTHING FASTER THAN A MICROWAVE?
At nearly 60 years oldā¦ so, with time being in rather shorter supply than it was when I was younger ā¦ I have a relatively recently acquired predilection for trying to cut straight to the chase. Sigh. I guess thatāll have to change and Iāll just have to knuckle back down and do the work
Hello @frannie can you disabling play on awake and add a tiny script that does something like this: if(this.context.input.getPointerDown(0)) timeline.play() ?
Hmmmmmmā¦ it doesnāt like something about my latest efforts. Iām now being repeatedly prompted to redo the export setup each time I make any changes. So, Iām going to ditch this test project and make a new version. Iāll pop back with more info when I get sorted
Iāve made several new test projects (all collab sandboxes) to try the above suggestion in a fresh environment, but each time I get the following (attached)