I’m trying to create an FMOD instance event before Unity’s splash screen shows, so that I can play music that starts as soon as the game launches and plays over top of Unity’s splash screen. I’m using the attribute:
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]
which triggers a function to be executed before the splash screen is shown, as documented here: https://docs.unity3d.com/ScriptReference/RuntimeInitializeOnLoadMethodAttribute.html
The FMOD event is being created with:
FMODUnity.RuntimeManager.CreateInstance()
It is important to note that using this attribute, the function is called before the scene is loaded (meaning there is no StudioListener yet). I can confirm that my code to create the event instance is called before the Unity splash screen is shown, however no audio will play until the splash screen ends and the scene is loaded.
Is there a way to get FMOD to play audio before the scene is loaded and the StudioListener is added?
Hi - apologies for the delayed response.
When you submit API commands to the Studio system, they are enqueued in a buffer which is then submitted to the system to act on when the system updates - i.e. when Studio.System.update()
is called. In the FMOD for Unity integration, the system update is tied to MonoBehaviour.Update()
(line 548 of RuntimeManager.cs), and as a result isn’t called until your scene actually starts updating.
It’s fairly trivial to work around this, all you need to do is manually call update yourself once you’ve enqueued your commands:
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]
static void TestFunc()
{
EventInstance eventInstance;
eventInstance = RuntimeManager.CreateInstance("event:/Music/Level 02");
eventInstance.start();
eventInstance.release();
RuntimeManager.StudioSystem.update();
}
Give it a shot and let me know whether that resolves the issue for you.
This worked perfectly! I can now start a music track that plays alongside Unity’s splash screen. Thanks for your help!
1 Like