GameObject.Find not working?
Hey everyone! I'm not sure if this is working or not (as in if it is even skipping it) but in my game, it doesn't find a game object. The object is a clone of a prefab (they both are). They spawn at the same time but the one that it must find spawns before it. here is my code!
public GameObject body;
void Start()
{
body = GameObject.Find("PlayerBody");
}
any idea how I can get this to work? Thanks everyone in advance!
Answer by See_Sharp · Mar 17, 2016 at 02:58 PM
Clones of prefabs have "(Clone)" Appended to their name. Try searching for "PlayerBody(Clone)".
In the end I just got fed up with it and made of of them a parent to the other and then spawned them in just to detach them afterwards which words. Thanks for the answer though!
Cool :) Don't use GameObject.Find anyways, there are better designing templates to avoid this. It's a pretty big performance to iterate through all the scene objects, and comparing strings makes it even worse! ;)
Your answer
Follow this Question
Related Questions
What to use instead of GameObject.Find and GetComponent 2 Answers
Sharing ints,Camera position(MOba),warnings,Could loop a fuction in start??? 0 Answers
How can we be notified the moment an object is instanced in the scene ? 3 Answers
How to Parent a Camera to the Head Bone with No Camera Shake? 0 Answers