Author
Topic: GameObject variables in Prefabs (Read 2492 times)

I'm having some problems using variables containing GameObjects that are being referenced by Prefabs. If I directly drag and drop the gameobject into the send event action it will send the event but it doesn't seem to work if the gameobject is in a variable. I should also point out that the variables contain the prefab and directly dragging and dropping is from the hierarchy view.

I'm also having a similar problem with invoke method.

Added: It will also work if I do a broadcast. Would this cause any performance hit if I left it?Any ideas?

This is a limitation in Unity. Prefabs cannot store references to scene object (objects in the hierarchy view). Even if the UI allows it, the reference will not be saved. Actually if the UI allows it, it's a bug - I'll look into Send Event allowing this...

A common strategy is to find the GameObject at runtime and store it in a variable E.g. using the Find Game Object action.