When to create an instance? How to keep it permanently parented to a gameObject?


(Luis Antonio) #1

I’ve been creating instances of events and parenting them with AttachInstanceToGameObject() when I initialize the scene, but I’ realizing that they don’t play any sound when they are finally triggered and I also get the error:
"...has not had EventInstance.set3DAttributes() called on it yet!"

Then I read this answer here:
https://www.fmod.org/questions/question/attachinstancetogameobject-not-moving-the-sound-position/

When you use AttachInstanceToGameObject, the instance is added to a list of events that have Set3DAttributes called in the RuntimeManagers Update function. To ensure that instances aren’t being updated that do not need to be, there are a few conditions that can cause an instance to be removed from the list and not have their position updated: instance.isValid(), transform == null, and playbackState == stopped.

If the event isn’t playing by the time it does the check, it will be removed from the list and not updated.

Does that mean that unless I start() my instance the moment I do an AttachInstanceToGameObject(), then it will not be updated?
And if so, does that mean that I should not be defining instances if I’m not ready to start() them immediately?

My thought process was to initiate certain instances that will play often (e.g. door open/close) and parent them to a gameObject, so I know they will follow it and I just trigger them when needed, rather than always do a PlayOneShot().

But if they lose their positioning once they are stopped is making me wonder if I’m not using the defined workflow for fmod+Unity…


(Cameron Baron) #2

The behavior behind AttachInstanceToGameObject() will only update playing events, this is to reduce the amount of work done by the RuntimeManager. The only settings that get applied from this is EventInstance.set3DAttributes. In your case, it sounds like using set3DAtttibutes directly is going to work better for you.
Otherwise just making sure to call AttachInstanceToGameObject whenever you start the event will ensure the event is added back into the list of events to update.