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

**URL:** <https://qa.fmod.com/t/when-to-create-an-instance-how-to-keep-it-permanently-parented-to-a-gameobject/13886>\
**Category:** Unity\
**Created:** [May 18, 2018, 10:11pm UTC](https://qa.fmod.com/t/when-to-create-an-instance-how-to-keep-it-permanently-parented-to-a-gameobject/13886 "2018-05-18T22:11:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![facaelectrica](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/facaelectrica/32/105_2.png) [@facaelectrica](https://qa.fmod.com/u/facaelectrica)\
**Post date:** [May 18, 2018, 10:11pm UTC](https://qa.fmod.com/t/when-to-create-an-instance-how-to-keep-it-permanently-parented-to-a-gameobject/13886/1 "2018-05-18T22:11:50Z")

</div>

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:

> **[AttachInstanceToGameObject not moving the sound position](https://qa.fmod.com/t/attachinstancetogameobject-not-moving-the-sound-position/)**
>
> I’m working with unity, fmod 1.09.06 and the oculus spatializer and I have issues using AttachInstanceToGameObject. I have isolate the problem: i create the istance of the object. i call the AttachInstanceToGameObject. if i move the obj the...

> _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…

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [May 22, 2018, 4:32am UTC](https://qa.fmod.com/t/when-to-create-an-instance-how-to-keep-it-permanently-parented-to-a-gameobject/13886/2 "2018-05-22T04:32:20Z")

</div>

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.
