Is it ok to have many EventInstances if they are not playing sounds? Better to instantiate when needed?

Feeling confused and would like some clarification.

In my current project, there are audio instances that are always playing sound (e.g ambient, music) and for those, I create an EventInstance at the start of the level.
What I’m wondering, is how to deal with small objects that will play short sounds on player actions. For example, a book that can be picked up, opened, dropped, etc.

Currently, I’m creating an EventInstance() for each object that stays dormant until it’s used.
All effects for that object are contained in a specific fmod event (drop, pick up, etc) and I like how clean it is in the sense that I cannot call 2 sounds for the same object since it all goes through this specific instance.
But that means I have about 50 EventInstance but they only play a sound when called. Is that ok? Is that kind of setup what is expected?

Also, and the reason that led me to ask this question, is that with the latest FMOD, when I create these instances, since I don’t set3DAttributes() until the object will actually play a sound, is making the Console create 50+ warnings for each object saying variations of:

[FMOD] Instance of Event event:/Sfx/Objects/Book has not had EventInstance.set3DAttributes() called on it yet!

Would it make more sense to only create the EventInstance when I want to play the sound?
Or what I’m doing is OK and I should just set3DAttributes() even if I don’t need them atm?
Or this message is overzealous from FMOD?

Thanks in advance.

In nearly all circumstances, it is best to create event instances only when they are needed, and release them afterwards. This minimizes the memory and CPU required by your game.

Creating an instance of an event loads the sampledata for all the assets required by that event into memory. Because of this, creating your event instances far in advance of when they’ll be needed means that the memory required by those events’ assets will remain in use even when they’re not playing. It also means that monolithic events that cover every possible situation in which an object could make consume more memory and take longer to load than events that cover only a single situation in which an object could make sound.

Not updating 3D attributes when an event doesn’t need them shouldn’t cause any problems in itself. The warning exists because creating event instances and not immediately setting their 3D attributes and playing them is unusual, and therefore may not be deliberate.

1 Like

Thank you for such a clear explanation. Changing the system to only create instances for sounds that will be playing more than half of the time only!

Yeah, @facaelectrica do that. What I would recommend is to use FMODUnity.RuntimeManager.PlayOneShot(string eventPath) for all the OneShots that you’ve set up. It seems like most of your events are OneShots anyway, so you won’t be needing an Event Instance unless the event is a loop or if you want to set its parameters while it is playing. :+1: