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.

Viewing 20 posts - 1 through 20 (of 21 total)
  • Author
    Posts
  • #18603
    Tyler Fruge
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    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
    #18605
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    Hi Tyler, which part of the series are you at? Can you share your SceneTransition script as well?

    #18606
    Tyler Fruge
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    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));
            }
        }
    }
    #18611
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    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.

    #18612
    Ser Apustaja
    Level 6
    AI Assistant
    (BETA)
    Helpful?
    Up
    0
    ::

    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:

    1. 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.
    2. 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.
    3. 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.
    4. 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.
    5. 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 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!

    #18613
    Tyler Fruge
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    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.

    #18614
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    The WalkIntoNewScene() function in SceneTransition (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 a Debug.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));
    }
    #18615
    Tyler Fruge
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    still having the same problem.

    #18617
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    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?

    #18737
    Tyler Fruge
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    Ok, so this is what happens (please excuse the lag)

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

    Can you add the following into WalkIntoNewScene() in your PlayerController 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;
    #18760
    Tyler Fruge
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    ok that fixed the invincibility but i’m still having the same issue with the scenes

    #18764
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    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
    #18765
    #18769
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    @tylerfruge need you to share your ProjectSettings folder as well. I will be able to test your project once I get it.

    #18775
    #18777
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    @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
    #18778
    Tyler Fruge
    Level 5
    Participant
    Helpful?
    Up
    1
    ::

    ok so what do i set it to because i am still having the same issue

      1 anonymous person
    has upvoted this post.
    #18779
    Tyler Fruge
    Level 5
    Participant
    Helpful?
    Up
    1
    ::

    wait, disregard the last one i sent, i think i got it. just gonna take a little tweaking

      1 anonymous person
    has upvoted this post.
    #18780
    Tyler Fruge
    Level 5
    Participant
    Helpful?
    Up
    1
    ::

    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
    has upvoted this post.
Viewing 20 posts - 1 through 20 (of 21 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: