leegod
February 20, 2017, 9:01pm
1
So there are many times that I need to get reference of various gameobjects in hierarchy.
For example, to manipulating UI, turn it on/off, I normally use gameObject.SetActive(true/false).
Then we need to get reference of that gameobject at code.
How do you do this normally and what is good method?
I uses normally make the variable public and drag Hierarchy’s target gameobject and drop this to variable.
But unity is very fragile and there are many times that Scene file itself being crashed or all things inside hierarchy just being disappeared.
Then, at Start or Awake part in script, using GameObject.Find(“Name”) is more good way for get reference?
or another way?
Thanks.
leegod:
I uses normally make the variable public and drag Hierarchy’s target gameobject and drop this to variable.
But unity is very fragile and there are many times that Scene file itself being crashed or all things inside hierarchy just being disappeared.
I’ve not had problems doing this. I usually make my fields private and use the [SerializeField] attribute instead of making them public.
leegod
February 21, 2017, 10:46am
3
Any benefit of doing that? So can block unexpected change from other script?
So you make it SerializeField and drag hierarchy’s object to there?
leegod
February 21, 2017, 8:42pm
5
andymads:
Yes and yes.
Then how handle situation of scene crash?
And after made a prefab, prefab can’t preserve scene object registered variable.(become null)
What’s a scene crash?
We have several projects, some that are a few years old. We don’t have a problem with wired up references disappearing.
leegod
February 22, 2017, 12:06pm
7
Stored in external SSD, worked well in one computer, but when move computer, suddenly file crashes and scene file become 1kb, and not opened.
We’ve never experienced this. We store our projects (only Assets and ProjectSettings folders) on SVN repositories and occasionally check out to new computers and it all works fine.
leegod
February 22, 2017, 12:59pm
9
My project size is over 22 giga. Can you recommend SVN?
We don’t have experience with projects that size. Our biggest project is around 1Gb.