Moved my game reset; now trying to further my understanding on nullerror

So I feel like I must be missing something that was done in the code while messing about with resetting the game score(I have found a way around my issues yet am working at making sure I understand all this).
Where it was originally put in the sceneloader script when starting back at scene (0). I attempted to move this line of code to a different scene load which I created cause I am smashing all these tutorials into one project and desired to create a menu which was different then when entering the game.
‘’’
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class loadscriptzA : MonoBehaviour {

public void LoadNextScene()
{
    int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
    SceneManager.LoadScene(currentSceneIndex +1);
}
public void LoadStartScene()
{
    SceneManager.LoadScene(0);
    FindObjectOfType<GameSession>().GameReset();
}
public void LoadGameChoices()
{
    SceneManager.LoadScene(1);
    //FindObjectOfType<GameSession>().GameReset();
}

public void LoadBallBreakerGame()
{
    SceneManager.LoadScene(4);
}
public void LoadAdventureGame()
{
    SceneManager.LoadScene(8);
}
public void QuitGame()
{
    Application.Quit();
}

}
‘’’ * I am going to remove the LoadGameChoices. in this I had changed the (0) to (1) on the LoadStartScene. I just don’t know why if I put GameReset under a different load it throws me the nullerror. I have it // where I tried it and it was causing errors.

I edited this post in response to the below… Thanks for that reminder Nina, I really appreciate your help!!

Hi Ian,

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

Hope this helps :slight_smile:


See also;

1 Like

(Solved)Yay - think I figured it out! It looks like I have identified the reason. I found it while going through an old scene which I had attached to my number wizard… My Gamestatus Prefab was not attached to anything in the games scene, which is where that destroy was located, thus throwing an error. Another way to say GameSession script is missing during these scenes. Which doesn’t really matter as I don’t want the score there yet I will have to deal with this… If I put it in it wants to display a number which I don’t want in the scene and seems like an annoyance. Maybe I can remove the destroy function from the Gamesession script all together and make it something accessible always and not needing that to be present in other scenes?
Revisiting this, that is not exactly what I had to ; I had to make sure that the function that I am calling from a button to go to scene is appropriate for that stage- not use LoadStartScene, which has that GameReset in it unless it is from the end of my ballbreaker game… I think this is correct.

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

Privacy & Terms