Forum begins after the advertisement:
[Part 5] Scene Transition Errors
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [Part 5] Scene Transition Errors
- This topic has 50 replies, 4 voices, and was last updated 5 days, 16 hours ago by
Josiah Loh.
-
AuthorPosts
-
December 31, 2025 at 1:24 pm #19165December 31, 2025 at 9:17 pm #19166::
It sounds like you’re encountering issues with your player object not being properly instantiated or referenced during scene transitions, which is likely causing the
NullReferenceExceptionerrors.Given that the error occurs in the
Move()method, it’s possible that thePlayer_Stateor other related components are not being set up correctly when transitioning between scenes. Here are a few steps to troubleshoot and resolve the issue:-
Ensure Player State Initialization: Make sure that the
Player_State_Listcomponent is properly assigned to the player object in every scene. If the player object is instantiated in a new scene, ensure that it has all the necessary components attached before any methods that rely on them are called. -
Check Scene Transition Logic: In your
Scene_Transitionscript, ensure that the player object is fully initialized before calling any methods that depend on its state. You might want to delay the execution of theWalk_Into_New_Scenecoroutine until after the scene has fully loaded. -
Debugging: Add debug logs in the
Move()method to check ifPlayer_Stateor any other critical variables arenullwhen the method is called. For example:Debug.Log(Player_State); // Check if Player_State is null -
Singleton Pattern: Ensure that your singleton pattern for
Player_Controlleris functioning correctly. If the player object is destroyed and recreated during scene transitions, theInstancevariable may not point to the correct object. -
Scene Management: If you’re using
DontDestroyOnLoadfor your player object, ensure that it is not being duplicated when transitioning to a new scene. You can check for existing instances in theAwakemethod of yourPlayer_Controllerscript. -
Image Reference: In the image you provided, check if the player object is being instantiated correctly in the new scene. If it appears only in one scene, ensure that the scene transition logic is correctly handling the player object.
If you continue to experience issues, could you clarify whether the player object is set to
DontDestroyOnLoadand if you have any logic in place to prevent multiple instances of the player from being created? This information will help in diagnosing the problem further.December 31, 2025 at 10:50 pm #19167December 31, 2025 at 11:17 pm #19168::It seems that the issue arises because the player object is not set to
DontDestroyOnLoad, which means it gets destroyed when transitioning between scenes. To fix this, ensure that you callDontDestroyOnLoad(gameObject);in theAwakemethod of yourPlayer_Controllerscript.Here’s how it should look:
private void Awake() { if (Instance != null && Instance != this) { Destroy(gameObject); } else { Instance = this; DontDestroyOnLoad(gameObject); // Ensure the player object persists across scenes } }Make sure this line is present so that the player object remains in the scene when transitioning. After making this change, test the scene transition again to see if the
NullReferenceExceptionerrors persist. If they do, please provide any additional error messages or behaviors you observe.January 1, 2026 at 9:15 pm #19169::@nirvikrajbhandari send a copy of your project files over if you’re still unable to fix the issue.
January 2, 2026 at 9:58 am #19170January 2, 2026 at 7:17 pm #19171::Thanks for your patience and for sharing the additional information! Let’s address the
NullReferenceExceptionyou’re experiencing in thePlayer_Controllerat line 244.From the error log you provided, it suggests that the issue occurs while trying to call the
Move()function. This can happen if some components or variables within thePlayer_Controllerare not properly initialized or assigned before the scene transition.Steps to Resolve the Issue:
-
Check Player State Initialization: Since you mentioned the player character has a player state component, ensure that
Player_Stateis properly initialized in theAwakemethod. Make sure you’re not trying to access it before it has been set.void Awake() { // Ensure this is set Player_State = GetComponent(); if (Player_State == null) { Debug.LogError("Player_State is not attached to the Player_Controller."); } } -
Avoid Calling Move() in Cutscene State: In the
Move()method, you should already be checking if the player is in a cutscene. However, it’s good to ensure that no other parts of the code are callingMove()or accessing player variables when transitioning scenes:private void Move() { if (Player_State.Healing || Player_State.Cutscene) { Rigidbody.velocity = new Vector2(0, 0); return; } // Existing movement code... } -
Player Object Persistence: Since the player object is not set to
DontDestroyOnLoad, ensure that when you transition scenes, you instantiate your player correctly in every scene. You might be losing references if the player object is destroyed during the transition. -
Using Scene Manager to Maintain State: If you want to preserve the player state and avoid
NullReferenceExceptions, consider keeping the player object persistent between scenes:void Awake() { if (Instance != null && Instance != this) { Destroy(gameObject); // Avoid duplicates } else { Instance = this; DontDestroyOnLoad(gameObject); // Keep this object alive during scene changes } } -
Debugging Null Checks: Add debugging logs before the line numbers where the exceptions occur to determine which variable is null. For example:
Debug.Log("Checking Player_State: " + Player_State);
Analyzing the Video and Console Output:
From the video and the console output you provided, it seems that the player might be trying to access certain properties or methods while transitioning between scenes. Ensure that the transition logic properly waits for the scene to load before allowing player actions.
If you still encounter the issue after these adjustments, please look at the specific lines in the
Move()function and the context around line 244. If you can identify which variable is null, I can provide more focused help! Let me know how it goes!January 6, 2026 at 9:48 am #19175::Sorry if I sound impatient, but have you found a way to fix it? If not, is there anything else I can provide to help?
January 6, 2026 at 4:36 pm #19177January 6, 2026 at 4:47 pm #19178::Hi @nirvikrajbhandari, Josiah here. I’ve sent another request to access your Google Drive project folders. Once I can access them, I’ll take a look and work on resolving the issues on my end. Thanks!
January 7, 2026 at 10:06 am #19181January 9, 2026 at 2:47 pm #19186::Sorry, I didn’t see your request. I have shared access now. Thank you!
I have sent a request to you as well. I will have a look at the files for you. Apologies for the delay.January 9, 2026 at 5:46 pm #19187::Hi @nirvikrajbhandari, I wasn’t able to find any new solutions beyond what Terence and Ser Apustaja have already suggested. Since the project was shared through Google Drive, the Unity project became corrupted when opened, which has made it difficult to work with reliably. With the current state of the project that I have access to, it’s not possible for me to accurately figure out where exactly the issues lie. Sorry for the inconvenience, and thank you for your patience.
January 10, 2026 at 10:09 am #19188::Oh ok, don’t worry and thank you for trying to help. I also sent access to Terence as well. Thank you!
January 10, 2026 at 10:17 am #19189::You’re welcome! I’m glad to hear that you’re working with others to resolve the issue. If you or Terence have any further questions or need additional assistance, feel free to reach out. Good luck with your project, and I hope you get everything working smoothly!
January 11, 2026 at 2:50 pm #19190::Oh ok, don’t worry and thank you for trying to help. I also sent access to Terence as well. Thank you!
@nirvikrajbhandari your project files don’t include all of your files, so we can’t test it out. I will be releasing a video covering how you can put your project on GitHub, to ease filesharing and ensure that all your files get transferred. Google Drive isn’t the best tool for this.January 11, 2026 at 9:43 pm #19191::Oh ok. Also, I just realized I uploaded my folder as a regular folder should I have uploaded it as a zip or is that ok?
January 11, 2026 at 10:17 pm #19192::It’s generally better to upload your project as a zip file, as it ensures that the entire folder structure and all files are preserved in one package. This makes it easier for others to download and access your project without missing any files. However, if the regular folder is accessible and contains all necessary files, it should be fine for now.
If you have any specific concerns about the contents of the folder or if you think some files might be missing, please let me know!
January 12, 2026 at 9:15 pm #19193::Yes, zip is an option, but it will be better if you put your project into GitHub. Here’s the guide — the first video by itself covers how to put your project onto GitHub, and the second video shows you how to add other collaborators into your project.
January 14, 2026 at 11:17 am #19198::I don’t know if I did it correctly. But here is the link for the GitHub page. Thank you!
-
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: