I have lots of 3D events in my scene in unity, will it take up CPU or memory when player cannot hear them?

I place lots of 3d events in my scene, these events will be loaded when players enter this scene. I am worried about the memory and cpu usage if these events will be played all the time whether players can hear them or not.

Ultimately I can’t make a judgement on your specific case without a lot more info, but I would recommend against premature optimization. If you do find yourself running into issues, connect to your game with Live Update and record a profiler session, which should allow you to diagnose potential performance issues.

That said, there are a number of potential things to keep in mind:

  • When creating your event instances, how many assets need to be loaded? You may wish to load assets in advance if you need to ensure an exact playback start time, especially if you’re loading many assets at once
  • How many assets are being streamed? Streamed assets aren’t loaded into memory in their entirety, but are streamed piecemeal on-demand, which saves on memory usage but increases CPU usage and disk I/O
  • You may wish to set a max instance limit for the event in the “Event Macros” section (bottom right of the Event Editor) so that only a certain number are playing at any given time. The “Virtualize” stealing mode can also be used to allow FMOD to stop producing output for event instances that are the least audible, and resume output when they stop being the least audible, which will likely be useful for your use-case

My 3D event will be loaded when GameObject is Instantiated, but it is heard depending on whether FMOD Listener position is in its Distance range. Is it possibile that this event can go to vittual track (or [“Virtualize” stealing mode] ? ) to save memory use?

It’s possible to either have the event go virtual or stop, but it would depend on what exactly the desired behavior is.

However, it’s worth noting that virtualizing or stopping events typically has far more of an impact on CPU usage than memory usage. This is because a large amount of memory usage comes from the assets loaded in your banks that are played by your events. If you assets aren’t streams, then each event instance playing a given asset is playing the exact same asset from memory, and isn’t duplicating the asset. On the other hand, every event instance requires a certain amount of CPU usage to process, so stopping/virtualizing will reduce CPU usage. If you want to specifically reduce memory usage, you may want to look more specific partitioning of your events into banks, and more specific management of which banks are loaded and unloaded at run time.

That said, if you want the event to straight-up stop outside of a certain distance, you can enable the “Stop Events Outside Max Distance” setting in FMOD Unity’s settings. This will cause events being played by StudioEventEmitter components to stop once their distance from the listener exceeds their maximum attenuation distance. If you aren’t using the component, you can see the relevant code being used to check the distance in StudioEventEmitter.UpdatePlayingStatus().

Virtualization is a little more nuanced and complicated. Event-level virtualization is more of a means of managing which event instances are relevant to the listener by audibility/volume, instead of a way to virtualize event instances outside of a certain distance. If you want to have event virtualize outside of a certain distance, you should be able to achieve this by placing a spatializer on the event and specifying the max attenuation distance desired. Then, you can add FMOD_INIT_VOL0_BECOMES_VIRTUAL to the system initialization flags, which will cause channels that exceed the volume set with FMOD_ADVANCEDSETTINGS::vol0virtualvol to become virtual.

I would recommend reading over our Virtual Voices White Paper for more information on the Studio and Core API virtualization systems.

1 Like

Thank you so much! That’s the best solution!!!

1 Like