Now Here’s a wierd one, ok, so in a game i am working on, when you go to an area you are supposed to go to the position of an object… when I transform back to my starting level, the camera is thrown off of the FPS capsule… Why and/or what is causing this to happen?
LATER:
OK … I have noticed that when I go back to starting level, there are two FPC characters… I am using the dontdestroy onload thing, but why are there two FPS when i only started with one?
UPDATE/info… The village is a separate scene… there is a FPS character controller thing, that starts in Wildcat field(the main over world) and when i go through a certain trail, i am to load the village. and I want to be able to go to the field again without the bug i am having the bug of two FPS controllers… Now, the main camera that was added to the scene when i created, I removed because i don’t need it if there is already a FPS character… and I want the fps character to stay persistent between levels without creating another instance, or not creating one at all
Because, when you’re for the first time in your start scene, your FPS character will be created. When mark it “DontDestroyOnLoad”, your FPS character will remain while the start scene unloads.
When you load your start scene again, your FPS character is created again, because the scene is loaded.
There are actually two ways you could solve this.
use a static variable to save the current instance of your FPS controller, i.e
public class MyFPSController : MonoBehaviour {
private static MyFPSController _instance = null;
void Awake() {
// Check if we have assigned that variable, if so quit. This prevents a second copy of the same object
if(_instance!=null) {
Destroy(this.gameObject);
return;
}
// If we managed to get so far, no instance has been loaded previously, so assign this instance to the static variable
_instance = this;
// do your normal initialization
DontDestroyOnLoad(this.gameObject);
}
}
That’s imho the best way to solve it, as is doesn’t involve “GameObject.Find”, which can stop working if you rename your object or tag.
The other option is to use GameObject.Find(…) and if it’s null initialize the object, otherwise destroy it