Hello,
I have the following problem: Im trying to swap to a scene(„samplescene“) using GameObject(this skript is attached to it) wich uses „DontDestroyOnLoad“ Then I want it to get a refference to a GameObject(„housespawner“) which I will use for the next steps (inside „samplescene“) The loading of the scene works fine, but the .Find method doesnt work in NewGame() which is confusing to me because the same command works if im manually doing it with Update()/GetKeyDown after I loaded the scene (Update() is just there,to show you the way it worked). So wheres the cause of not working when Im using it in the same method as SceneManager.LoadScene and what could be a solution. Or is there a even better way by not using .Find (I know its not very perfect). I was also searching for a way to refference housespawner immedialty, but the Gameobject with the skript is in the scene before. Thanks
public class GameManager : MonoBehaviour{
public void NewGame()
{
SceneManager.LoadScene("SampleScene");
houseSpawner = GameObject.Find("houseSpawner");
}
void Update()
{
if (Input.GetKeyDown(KeyCode.K))
{
houseSpawner = GameObject.Find("houseSpawner");
}
}
}