Forum begins after the advertisement:


[Part 6] Trying to spawn the player in a randomly generated map

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [Part 6] Trying to spawn the player in a randomly generated map

Viewing 8 posts - 21 through 28 (of 28 total)
  • Author
    Posts
  • #15867
    C Vagdalt
    Level 4
    Participant
    Helpful?
    Up
    0
    ::

    yes ofcourse,

    private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
    {
        Debug.Log("OnSceneLoaded called for scene: " + scene.name);
    
        WalkerGenerator walkerGenerator = FindFirstObjectByType<WalkerGenerator>();
        if (walkerGenerator != null)
        {
            walkerGenerator.SpawnPlayer();
            Debug.Log("WalkerGenerator found and SpawnPlayer called.");
        }
        else
        {
            Debug.LogError("WalkerGenerator not found in the scene.");
        }
    
        EnemySpawner enemySpawner = FindFirstObjectByType<EnemySpawner>();
        if (enemySpawner != null)
        {
            enemySpawner.InitializeSpawner();
        }
        else
        {
            Debug.LogError("EnemySpawner not found in the scene.");
        }
    }
    #15868
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    This doesn’t seem like the code that has the error.

    #15902
    C Vagdalt
    Level 4
    Participant
    Helpful?
    Up
    0
    ::

    when i click on the highlighted error message it takes me too my sceneloader script instead of the walkergenerator script

    all the other errors also take me to other scripts than walkergenerator

    View post on imgur.com
    #15903
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    The first error says to add a WalkerGenerator component to your Scene. Maybe you can try that first.

    #15912
    C Vagdalt
    Level 4
    Participant
    Helpful?
    Up
    0
    ::

    my walker generator object is already in the scene

    View post on imgur.com
    #15913
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    You can try delaying OnSceneLoaded() by a single frame and see if the WalkerGenerator can be found like this. The function may be running before your GameObjects are properly initialised:

    private IEnumerator OnSceneLoadedDelayed(Scene scene, LoadSceneMode mode)
    {
        Debug.Log("OnSceneLoaded called for scene: " + scene.name);
    
        WalkerGenerator walkerGenerator = FindFirstObjectByType<WalkerGenerator>();
        if (walkerGenerator != null)
        {
            walkerGenerator.SpawnPlayer();
            Debug.Log("WalkerGenerator found and SpawnPlayer called.");
        }
        else
        {
            Debug.LogError("WalkerGenerator not found in the scene.");
        }
    
        EnemySpawner enemySpawner = FindFirstObjectByType<EnemySpawner>();
        if (enemySpawner != null)
        {
            enemySpawner.InitializeSpawner();
        }
        else
        {
            Debug.LogError("EnemySpawner not found in the scene.");
        }
    }
    
    private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
    {
        StartCoroutine(OnSceneLoadedDelayed(scene, mode));
    }

    The reason why I’m focusing on fixing the WalkerGenerator first is because it may be causing the other errors.

    #15915
    C Vagdalt
    Level 4
    Participant
    Helpful?
    Up
    0
    ::

    the walkergenerator error is now gone. i still have a lot of errors though

    i’ll also post a video of the layout of the scenes i have in the game so you can see when the errors appear

    View post on imgur.com
    #15923
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    You will need to find the lines that are causing the error, and figure out what is causing the message to trigger. Usually, one of your variables are either not set or set wrongly.

Viewing 8 posts - 21 through 28 (of 28 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: