Player Not Instantiating

It Instantiates the player at the start of the game. However, when the next scene is loaded it doesn’t re-Instantiate the player. Am I over-looking something? It was working before.

public class GameMaster : MonoBehaviour{
   
    public Camera mainCamera;

    private GameObject playerCharacter;
    private GameObject headsUpDisplay;
    private GameObject eventSystem;
    private GameObject pc;
    private GameObject cam;
    private PlayerCharacter pcScript;
    private Vector3 playerSpawnPointPos;

    void Awake(){
        DontDestroyOnLoad(this);
    }

    void Start () {
        playerSpawnPointPos = ChooseSpawnPoint.PickSpawnPoint(Application.loadedLevelName.ToString(), PlayerPrefs.GetString("Last Zone", "PalletTownIntro"));
        playerCharacter = (GameObject)Resources.Load("Prefabs/Player Character Prefab");
        pc = Instantiate(playerCharacter, playerSpawnPointPos, Quaternion.identity) as GameObject;
        Debug.Log(Application.loadedLevelName);
        if(Application.loadedLevelName == "MainMenu" || Application.loadedLevelName == "CharacterGeneration"){
            pc.GetComponent<Movement>().enabled = false;
            pc.GetComponent<PokeBallThrow>().enabled = false;
            pc.GetComponent<PokemonEncounter>().enabled = false;
        }
        pc.name = "Player Character";
        pcScript = pc.GetComponent<PlayerCharacter>();

        cam = Instantiate(mainCamera, Vector3.zero, Quaternion.identity) as GameObject;
        if(Application.loadedLevelName != "MainMenu" || Application.loadedLevelName != "CharacterGeneration"){
            LoadCharacterData();
            headsUpDisplay = (GameObject)Resources.Load("Prefabs/HUD Prefab");
            eventSystem = (GameObject)Resources.Load("Prefabs/Event System Prefab");
            Instantiate(headsUpDisplay, Vector3.zero, Quaternion.identity);
            Instantiate(eventSystem, Vector3.zero, Quaternion.identity);
        }
        pcScript.LastZone = Application.loadedLevelName.ToString();
        SaveCharacterData();
    }

Specifically:

In all, you’re gonna want to move that logic to OnLevelWasLoaded()

1 Like

Hmm. Good to know. Thanks!

No worries man. Good luck on your adventure, and remember to always read the docs thoroughly. :slight_smile:

PS: HUGE fan of pokemon games. xP

1 Like

Any idea why lines 23, 24, and 25 aren’t working? Their parameters ARE being met…but they’re not disabling those componenets.

Well, it could be before you’re trying to disable their components before they are ever enabled to begin with. I believe OnLevelWasLoaded is called before Start(), which would make me believe that you’re disabling them, then they are being enabled again. It isn’t that the code isn’t being called, it’s that it’s being called while they’re still disabled in the first place. There are a few options here… You could implement a bool to disable their movement on Start()… OR, you could implement a coroutine to disable them after like 0.1f seconds.