Hi… is there a best/preferred way to get a timeline to run when a user hits the AR or VR buttons?
I have a script that successfully starts the timeline running ‘on user interaction’. However, I’ve noted that if a user is wearing a headset and doesn’t interact with the scene before hitting the VR button the timeline doesn’t play and, instead, everything in the VR environment is static.
The script I’m currently using is:-
export class Play extends Behaviour
{
@serializable(PlayableDirector)
timeline? : PlayableDirector;
update(){
if(this.context.input.getPointerDown(0)) this.timeline?.play();
}
}```
[Original Post on Discord](https://discord.com/channels/717429793926283276/1075696161882640384)
*by user 908977119781060648*
Not in update do that in start() (you only want to receive the event once, if you put the code like this in update you will subscribe 1000s of times to the event (every frame) and your app will be very very slow over time.
You might also just hook into the function that the audiolistener is using. Sorry as im currently travelling its a bit slow/hard to look things up and help ^^ it will be better again next week
export class Play extends Behaviour
{
@serializable(PlayableDirector)
timeline? : PlayableDirector;
awake(){
window.addEventListener("pointerdown", () => this.timeline?.play())
}
}```
... works brilliantly well for desktop and VR. However, it doesn't appear to start the timeline in AR.
That's totally *not a deal-breaker* though. I'm absolutely delighted that pretty much everything's working as hoped-for. That'll do for me for now... I'm more than content with how things are going 😊 😊 😊 😊 😊 Huge thanks for all your help!
*by user 908977119781060648*
import { WebXREvent } from "@needle-tools/engine/engine-components/WebXR";
export class Play extends Behaviour
{
@serializable(PlayableDirector)
timeline? : PlayableDirector;
awake(){
window.addEventListener("pointerdown", () => this.timeline?.play())
}
start() {
WebXR.addEventListener(WebXREvent.XRStarted, () => this.timeline?.play())
}
}```
... but unfortunately it still doesn't seem to start the timeline in AR. However, it could be that my phone is an issue; so I'm not going to worry too much for now, in case it's working normally but just not for me 🙂
*by user 908977119781060648*
I dont think its your phone. Maybe the problem is caused by the fact that the timeline is disabled while the ar scene is placed and that happens after the play call.