SpawnedAtRuntime question

Why is it, that I cannot drop SpawnedAtRuntime on the enemy prefabs, even though “parent” is shown in the inspector ? It works if dropping it in on the various enemy instances, but not the prefab. What if I add more enemy ships - will I have to remember to add the SpawnedAtRuntime to each new enemy I place in the scene?

Hi there, I just ran into this. I think it’s because you can’t put a reference to an object in your scene on a prefab. The prefab wouldn’t work in another scene if that empty game object wasn’t also in the scene.

You can set the variable parent in your code to point to the empty gameobject transform by using gameObject.Find(“nameOfYourEmptyGameObject”).transform but you have to use it in Awake() or Start().

Privacy & Terms