Skip to content

prefabs losing references

Ask for help here ;)

prefabs losing references

Postby RichMakeGame » 21 Apr 2012, 20:44

I have this problem:

1- from a fresh scene, I create an empty gameobject
2- create another gameobject (call it, vizioobject for example)
3- create a graph on vizioobject, and drag in the empty gameobject, creating a link to its transform
4- save the graph and the scene

ok, all is fine so far.

5- drag vizioobject into the project heirarchy to create a prefab
6- view the prefab's graph. the connection is broken and the LB says 'missing'

this is a pretty big problem for me right now. even if I remake the connection, save the graph and unity, when I reload the connection is broken. Note that I am clicking on and accessing the graph using the prefab. it's a nightmare right now, I'm trying to compete in ludum dare and this breaks my game
RichMakeGame
 
Posts: 49
Joined: 16 Feb 2012, 20:30

Re: prefabs losing references

Postby Neodrop » 22 Apr 2012, 11:21

It's just because Unity prefabs can't save the links to objects in the scene.
It can store the links only to objects from Project View (assets or other prefabs)
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Re: prefabs losing references

Postby RichMakeGame » 24 Apr 2012, 16:05

thanks, this seems like one of these things that's only obvious when you already know it :)

I've only ever see the drag-in method of accessing other objects in tutorials, so this not working was somewhat of a shock. could antares maybe detect when you're trying to do this in a prefab object connected to the game heirarchy and throw up a warning? there's no indication at the time that you're doing something wrong
RichMakeGame
 
Posts: 49
Joined: 16 Feb 2012, 20:30

Re: prefabs losing references

Postby nzen » 24 Apr 2012, 18:45

Yes, tutorials will drag them in to not overcomplicate the tutorial. The best way will be a GameObject.Find block or create a variable for the Transform. I use a seperate script for all vars so they show in the inspector, then use GetComponent block on that script, instead of using Antares' Local Var inspector.
nzen
 
Posts: 39
Joined: 12 Dec 2011, 20:43

Re: prefabs losing references

Postby RichMakeGame » 24 Apr 2012, 19:37

thanks nzen- could I ask you to elaborate a little on that setup?

so, you have one script which contains (all?) your game variables- then for every other script do you run a find on start to locate it and create the reference? I can't quite visualise your method

thanks!
RichMakeGame
 
Posts: 49
Joined: 16 Feb 2012, 20:30

Re: prefabs losing references

Postby nzen » 24 Apr 2012, 21:52

It depends on what you are trying to do, but the option here seems to be just doing a GameObject.Find on Start with the name. The prefab will only save stuff from itself and children, so maybe parenting them both to an empty gameobject will fix it, but it depends what you're trying to do in your game.
nzen
 
Posts: 39
Joined: 12 Dec 2011, 20:43

Re: prefabs losing references

Postby Trezvie » 27 Nov 2015, 14:22

Very good and informative exchange .. Thank you!
Trezvie
 
Posts: 13
Joined: 26 Nov 2015, 15:32


Return to HELP!!!

Who is online

Registered users: No registered users