I often use a Playable Director in my scenes which begins playing the requisite content when a user interaction takes place triggering the following script (which I attach to the main camera):-
Behaviour,
PlayableDirector,
serializable,
WebXR,
} from "@needle-tools/engine";
import { WebXREvent } from "@needle-tools/engine";
export class Play extends Behaviour {
@serializable(PlayableDirector)
timeline?: PlayableDirector;
awake() {
window.addEventListener("pointerdown", () => {
if (this.timeline) {
this.timeline.playOnAwake = true;
this.timeline.play();
}
});
}
start() {
WebXR.addEventListener(WebXREvent.XRStarted, () => this.timeline?.play());
}
}```
This has always worked fine with the animated stuff, but I could really use some help and advice regarding video content.
I've got a 'combined video' (based on the brilliant 'merged/alpha' Needle sample) in my scene and I'd like it to only start playing when the user interaction takes place.
I've unchecked the video's 'play on awake' component setting (see screenshot) but that only results in the vid displaying as a blank white rectangle when the user interaction tiggers the Playable Director, because obviously I haven't added anything to the script to tell the video to play.
Could some kind (and clever š ) soul tell me what I'd need to add to the script to get the vid to start?
Thanks in advance for your time and expertise š„°
![01.jpg](https://cdn.discordapp.com/attachments/1176938022562963536/1176938022915293267/01.jpg?ex=65d63373&is=65c3be73&hm=d1e8bfb169800df84845038f3641db6bb38c9d8b8a582336037fbb39c8e3b068&)
[Original Post on Discord](https://discord.com/channels/717429793926283276/1176938022562963536)
*by user 908977119781060648*
Hmmmmm, nope sadly that doesnāt address what Iām trying to achieve. Iāve tried that, plus a few variations, and I still canāt get it doing what I want.
I probably didnāt ask the right question in the right way.
Basically, if I have the vid set to āplay on awakeā it displays and runs perfectly. However, very deliberately all the other content thatās on the PlayableDirector timeline (and which is triggered by the script above) only begins playing when the user interaction takes place. By which time, the vid is badly out of sync with the other content as itās already been playing.
What I think I need, is something added to the script to tell the vid to only start playing when the āpointerdownā user interaction takes place.
Maybe? Perhaps??? Really not sure if Iām on the right track???
One change recently caused audio autoplay to stop working if the audio became active before any user interaction had happened. This might have also affected videos - it should be fixed with 3.25.3
Nope, unfortunately that hasnāt made any difference. The vid displays and runs fine, but I still need it to start playing from the very beginning of the video when the user interaction occurs.
Nope, still not there. The script now runs fine but if the video has the āPlay on Awakeā setting disabled it just displays as a white rectangle again.
As saidā¦ the vid renders absolutely perfectly (with the alpha/transparency looking fabulous ) when itās set to āPlay on Awakeā. Sadly, though, I really do need the video to go right back and start from its beginning when the user interaction occurs, otherwise itās wildly out of sync with the rest of the scene content thatās triggered to play by that same interaction.
Big, big thanks for all the suggestions thus far, though. Theyāre greatly appreciated, I kid you not!
Iāll put my thinking hat on and see if I can maybe find a different way to achieve things