Reference to the animated target breaks on new scene loading

I am using state driven cameras for each of my levels in the game with the animated target as the “Player” object. Now when I am progressing through the game, as soon as I advance to the next level, the “Player” object reference in “Animated Target” of the state driven camera script becomes null in the state driven cameras, and thus the view defaults basic camera. I know the reason for this is that all the objects get destroyed and instantiated again in new scene. But I can’t use the DontDestroyOnLoad approach as the camera sizes differ between levels depending on the size of the stage. Is there a way to do this? I hope I am clear in what I am asking.

I am stuck on this thing for last few days. Tried to research but couldn’t find anything

As each scene has its own camera, either each camera has its own copy of the script driving the camera or, your script has to go out and find the camera each time you load a new scene. Either way, your camera needs to grab a reference to the player for the scene its located in (ie: GameObject player = FindWithTag("Player"))

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms