Was just wondering if it was at all possible to keep music playing whilst/after changing scene?
So if I go from scene 1 through to scene 2 and a song is 58 seconds in, am I able to either
a) get information to the new scene to start at 58 seconds?
b) have the music script ‘scene independent’?
Many thanks in advance,
You can do that by adding the sound component to the app root entity, that way it won’t get destroyed when you dispose the previous scene.
That would be here:
Thanks for your quick reply @Leonidas.
I think I almost there. How do I access the sound component once I have changed scenes?
i.e. How do I access components that have been appended to app root entity?
Is there anyway rather than adding a component to the root entity I can just add an entity?
Thanks in advance,
I think you can keep using the same notation, that is the root entity of the application, not the scene. So it won’t be affected by scene changes:
Hmm, not sure if there is any other way. You could try creating an entity in code, that isn’t appended to any other entity and add the sound component. For rendering and anything else that entity won’t be of much use, but curious if it can still activate its sound component and play sounds (I haven’t tried that).
Thank you very much yet again.
I realised about 30 seconds ago I was being a bit of an idiot and it was the root ‘ENTITY’ so I can access its components like I would any other entity. Will put all I have learned into practice now and hopefully should be good to go.
Again, many thanks,
To anyone who may be looking at this in the future, above is the correct approach. Here is step by step what to do.
- Create a script, that adds a sound component to the root entity.
- Add whatever audio you want to slots in the root entity sound component.
var song = this.app.assets.get(assetID);
- Access this asset as you would with any normal entity.
Again, thanks @Leonidas for your help assisting me in this matter.
That’s great, thanks for sharing a detailed solution here @James_Austin.