- Home /
Updating a prefab attached to a prefab on instantiation.
At the moment I'm working on a FPS. I have my GUI in the hierarchy, and my Spawn points there also. I have made my player a prefab also since he needs to respawn whenever he is killed. I realised I had to make the GUI and Spawn Points prefabs to attach them to my player prefab, seeing as you can't do that with hierarchy objects.
However, I'm running into another issue now. When I instantiate the player on start up, the GUI or Spawn points don't link themselves to the player correctly.
Answer by Aequitas · Jun 24, 2010 at 01:50 PM
I have managed to solve this issue, I don't know why it didn't occur to me earlier. You are able to leave the members of the prefab at null, and simply assign them to Hierarchy objects in either the Start() or Awake() function.
Answer by xeophin · Jun 24, 2010 at 01:36 PM
You could tag your player prefab with a special tag (i.e., "player"). This way, you can use GameObject.FindWithTag("player")
in order to let the other objects reference the player object.
Answer by Ashkan_gc · Jun 24, 2010 at 02:21 PM
you can make them children of the player to instantiate and destroy them with the player if there is no problem with doing this. otherwise you should set the references at runtime. use GameObject.Find and many other functions in Object class and GameObject class to find objects using their name, components and tag. then simplly get the script that you want using GetComponent and set it's variables. you can make objects children of another using transform.parent too. if you use the script to set it's own variables, obviously you don't need GetComponent.
Your answer
Follow this Question
Related Questions
Instantiated prefab scale is wrong. 2 Answers
Script is reading from prefab instead of instance 1 Answer
How to attach a script to a static Tree Prefab? 1 Answer
How do i make a cube "slide"and fixed on a rail? 0 Answers
Player spawn after touching 0 Answers