Forum begins after the advertisement:
[Part 5] Issue with scene transitions.
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [Part 5] Issue with scene transitions.
- This topic has 18 replies, 3 voices, and was last updated 4 days, 22 hours ago by
Tyler Fruge.
-
AuthorPosts
-
August 5, 2025 at 11:21 am #18603::
every time i go from cave 1 to cave 2, the player keeps blinking. also, once i go to cave 2 and try to go back to cave 1, i am in cave 1 for a split second before it teleports me back to cave 2
View post on imgur.com
August 6, 2025 at 11:09 pm #18605::Hi Tyler, which part of the series are you at? Can you share your
SceneTransition
script as well?August 7, 2025 at 3:03 am #18606::I am on Part 5, didn’t do the lighting yet, but here is my scene transition code:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class SceneTransition : MonoBehaviour { [SerializeField] private string transitionTo; //Represents the scene to transition to [SerializeField] private Transform startPoint; //Defines the player's entry point in the scene [SerializeField] private Vector2 exitDirection; //Specifies the direction for the player's exit [SerializeField] private float exitTime; //Determines the time it takes for the player to exit the scene transition // Start is called before the first frame update private void Start() { if (GameManager.Instance.transitionedFromScene == transitionTo) { PlayerController.Instance.transform.position = startPoint.position; StartCoroutine(PlayerController.Instance.WalkIntoNewScene(exitDirection, exitTime)); } StartCoroutine(UIManager.Instance.sceneFader.Fade(SceneFader.FadeDirection.Out)); } private void OnTriggerEnter2D(Collider2D _other) { if (_other.CompareTag("Player")) { GameManager.Instance.transitionedFromScene = SceneManager.GetActiveScene().name; PlayerController.Instance.pState.cutscene = true; PlayerController.Instance.pState.invincible = true; StartCoroutine(UIManager.Instance.sceneFader.FadeAndLoadScene(SceneFader.FadeDirection.In, transitionTo)); } } }
August 7, 2025 at 1:44 pm #18611::For the scene transitioning back from Cave 2, make sure that the spawn location you place on Cave 2 doesn’t overlap with the Scene Transition collider back to Cave 1. Otherwise, my guess is that the
WalkIntoNewScene()
is hitting the collider and bringing you back to Cave 1.As for the blinking, can you select your Player in the Hierarchy so that we can see the Sprite Renderer component in the Inspector? We have to determine what component is changing the colour, and I’m guessing the Sprite Renderer is doing it. Then, we have to see what might be controlling the sprite renderer to change the colour.
August 7, 2025 at 1:51 pm #18612::It looks like you’re working on a scene transition issue in your game, specifically with the transition from Cave 2 back to Cave 1. Here are a few steps to help you troubleshoot the problems you’re facing:
-
Check Spawn Location in Cave 2:
- Ensure that the spawn point in Cave 2 is placed far enough away from the Scene Transition collider that leads back to Cave 1. You can do this by selecting the spawn point in your scene view and moving it to a location that doesn’t intersect with the collider.
-
Verify Collider Settings:
- Double-check the collider settings on both the spawn point and the Scene Transition. Make sure that the collider on Cave 1 is set up correctly and is only meant to trigger when the player actually wants to transition back.
-
Inspect the Sprite Renderer:
- Select your Player object in the Hierarchy and look for the Sprite Renderer component in the Inspector. Check the following:
- Color Property: Make sure the color is set to the intended color and isn’t being altered by another script or component.
- Material: Confirm that the material assigned to the Sprite Renderer is not causing the blinking effect. Sometimes, materials with shaders can cause unexpected visual effects.
- Select your Player object in the Hierarchy and look for the Sprite Renderer component in the Inspector. Check the following:
-
Check for Scripts Changing Color:
- Look for any scripts attached to your Player that might be changing the color of the Sprite Renderer. You can search for calls to
GetComponent().color
in your scripts. If you find any, review the logic to see if they’re triggering under unexpected conditions.
- Look for any scripts attached to your Player that might be changing the color of the Sprite Renderer. You can search for calls to
-
Debugging the Blinking Issue:
- If the blinking persists, consider adding debug logs in your color-changing script to determine when and why the color is being altered. For example:
Debug.Log("Color changed to: " + spriteRenderer.color);
- This will help you trace the flow and identify if it’s being called multiple times unintentionally.
- If the blinking persists, consider adding debug logs in your color-changing script to determine when and why the color is being altered. For example:
If you follow these steps and still experience issues, feel free to provide more specific details about your setup or any scripts you’re using, and we can dig deeper into the problem!
August 10, 2025 at 6:54 am #18613::Ok so, when i go to new scenes, the player is forever invincible, and i tried moving the start points around and i am still having the same issues.
August 10, 2025 at 3:00 pm #18614::The
WalkIntoNewScene()
function inSceneTransition
(highlighted below) is supposed to untoggle your invincibility and set the cutscene back to false:public class SceneTransition : MonoBehaviour { [SerializeField] private string transitionTo; //Represents the scene to transition to [SerializeField] private Transform startPoint; //Defines the player's entry point in the scene [SerializeField] private Vector2 exitDirection; //Specifies the direction for the player's exit [SerializeField] private float exitTime; //Determines the time it takes for the player to exit the scene transition // Start is called before the first frame update private void Start() { if (GameManager.Instance.transitionedFromScene == transitionTo) { PlayerController.Instance.transform.position = startPoint.position; StartCoroutine(PlayerController.Instance.WalkIntoNewScene(exitDirection, exitTime)); } StartCoroutine(UIManager.Instance.sceneFader.Fade(SceneFader.FadeDirection.Out)); } private void OnTriggerEnter2D(Collider2D _other) { if (_other.CompareTag("Player")) { GameManager.Instance.transitionedFromScene = SceneManager.GetActiveScene().name; PlayerController.Instance.pState.cutscene = true; PlayerController.Instance.pState.invincible = true; StartCoroutine(UIManager.Instance.sceneFader.FadeAndLoadScene(SceneFader.FadeDirection.In, transitionTo)); } } }
Can you check if the
Start()
function fires when you enter a new Scene? You can add aDebug.Log()
into it to ascertain it:// Start is called before the first frame update private void Start() { Debug.Log("Entering new Scene..."); if (GameManager.Instance.transitionedFromScene == transitionTo) { Debug.Log("Calling WalkIntoNewScene()"); PlayerController.Instance.transform.position = startPoint.position; StartCoroutine(PlayerController.Instance.WalkIntoNewScene(exitDirection, exitTime)); } StartCoroutine(UIManager.Instance.sceneFader.Fade(SceneFader.FadeDirection.Out)); }
August 11, 2025 at 2:34 am #18615August 11, 2025 at 12:39 pm #18617::Yes, the changes only print log messages. They don’t fix the issue because we don’t know where the issue is yet.
Does the “Calling WalkIntoNewScene()” message appear on your Console when you enter a new Scene?
August 21, 2025 at 4:30 am #18737August 21, 2025 at 1:32 pm #18741::Can you add the following into
WalkIntoNewScene()
in yourPlayerController
script as well?public IEnumerator WalkIntoNewScene(Vector2 _exitDir, float _delay) { pstate.invincible = true; Debug.Log("Walking into new Scene cutscene begin."); //If exit direction is upwards if(_exitDir.y > 0) { rb.velocity = jumpForce * _exitDir; } //If exit direction requires horizontal movement if(_exitDir.x != 0) { xAxis = _exitDir.x > 0 ? 1 : -1; Move(); } Flip(); yield return new WaitForSeconds(_delay); pstate.invincible = false; pState.cutscene = false; Debug.Log("Walking into new Scene cutscene end."); }
My suspicion is that these 2 lines at the end are failing to fire because your
WaitForSeconds()
above does not finish executing.pstate.invincible = false; pState.cutscene = false;
August 22, 2025 at 3:42 am #18760August 22, 2025 at 7:25 pm #18764::Can you zip up your project files as per the instructions in the article below and share your project with me on Google Drive? Will be easier for me to pinpoint the project by looking at it in Unity itself.
How to package and transfer your Unity project from one device to another
August 23, 2025 at 6:21 am #18765::ok here are the files.
https://drive.google.com/file/d/1OoQZuzk7lOjj6awt7th0fH0tLp7dx-Jt/view?usp=sharing
August 23, 2025 at 9:54 pm #18769::@tylerfruge need you to share your ProjectSettings folder as well. I will be able to test your project once I get it.
August 24, 2025 at 2:37 am #18775::ok, here is the folder
https://drive.google.com/file/d/1nVB8Hy8tMwCZLjGsTOhQaI_nePmCphlb/view?usp=drive_link
August 24, 2025 at 3:04 pm #18777::@tylerfruge found your issue. You did not assign the start point for all your Scene Transition objects, so they always spawn at (0, 0, 0) and cause issues when you transition.
View post on imgur.com
August 25, 2025 at 1:34 am #18778::ok so what do i set it to because i am still having the same issue
- 1 anonymous person
August 25, 2025 at 1:41 am #18779::wait, disregard the last one i sent, i think i got it. just gonna take a little tweaking
- 1 anonymous person
August 25, 2025 at 5:16 am #18780::Ok so i tried added the numbers but i am not being transported to where i need to go.
what numbers do i need to set the start points to?
UPDATE: ok, i got it, i just had to move the starting points around a little. thanks!
- 1 anonymous person
-
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: