- Home /
Player using Dont destroy on load
Hi,
In order to get around some problems with initialization happening twice (because of some parameters being static and what not) I thought it would be a good idea to make our player character use the Object.DontDestroyOnLoad functionality.
The description reads as follows:
Makes the object target not be destroyed automatically when loading a new scene.
This means that when I load a new level the old player controller is just moved to the new scene without deleting it.
In all the scenes that we use we have a very generic trigger/entity setup that revolves around dragging in the references to the transforms of whatever you want to perform any action on. One example is that when our player character picks up a gadget we will teleport the gadget to the players hand-transform and play a "I found a gadget" animation on the player that moves the hands into the air (with the newly attached gadget). The problem now is that all of those generic entities have lost their reference to our player because we cant really drag in the players hand into the "transform" slot in the entity anymore because the player is not present in the scene anymore (since it gets transferred over from the previous scene instead).
I am curious if there is a smart way around this, or do I really have to create separate entities for everything that has to do with the player? (This is a HUGE task and I would like to hear a good way around this issue).
Answer by john-essy · Oct 27, 2011 at 11:38 AM
If i am reading this right you want to do this in the start of your scripts function Start() { gameObject.Find("Gadget").GetComponent("something"); }
but if you mean like it needs to be placed at the player hand just put everything you need in the players hands and turn of the renderers. Then you could do
var gadget = GameObject.Find("Gadget").renderer.enabled = true;
Your answer
Follow this Question
Related Questions
Setting Player positioning on a different loaded scene with Dont Destroy On Load attached. 0 Answers
Need enemy to follow only active character 0 Answers
Making a powerup that transforms player scale 1 Answer
Main Camera GetComponent doesn't work for a script? 0 Answers
Should I use DontDestroyOnLoad or prefab for player 1 Answer