Forum begins after the advertisement:


[part 5] scene transitions dont work

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [part 5] scene transitions dont work

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #12416
    Niyam Shah
    Participant

    my scene transitions are very buggy

    #12418
    Niyam Shah
    Participant

    Scene transitions:

    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;
            }
        }
    
        private void Update()
        {
    
        }
    
        private void OnTriggerEnter2D(Collider2D _other)
        {
            if (_other.CompareTag("Player"))
            {
                GameManager.Instance.transitionedFromScene = SceneManager.GetActiveScene().name;
    
                SceneManager.LoadScene(transitionTo);
            }
        }
    }
    

    Game manager:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class GameManager : MonoBehaviour
    {
        public string transitionedFromScene;
    
        public static GameManager Instance { get; private set; }
        private void Awake()
        {
            if (Instance != null && Instance != this)
            {
                Destroy(gameObject);
            }
            else
            {
                Instance = this;
            }
            DontDestroyOnLoad(gameObject);
        }
    
        // Start is called before the first frame update
        void Start()
        {
    
        }
    
        // Update is called once per frame
        void Update()
        {
    
        }
    }
    #12419
    Niyam Shah
    Participant

    So the issue is that i will transition between scene 1 and scene 2 but it happens strangely? I will transition to scene 2 to the coordinates of the effector in scene 1 even though ive set the start point to somewhere else, it doesn’t seem to do anything. Also when i try to repeat transition from scene 2 to scene 2, i will transition at my start point of scene 2 but all my midground sprites will disappear(the colliders are still there not the sprites)

    #12422
    Niyam Shah
    Participant

    ive tried to wend you images via imgur but they arent sending even though i followed the tutorial many times

    #12429
    Niyam Shah
    Participant

    View post on imgur.com

    location of my scene transition effector collider

    #12417
    Niyam Shah
    Participant

    So ive created a scene trasnition between scene 1 and scene 2. My character will go between these scenes but it doesn’t work as expected. My character will only transition to scene 2 to the coordinates of my scene transition collider in scene 1. My character won’t go to the start point though ive selected it in the inspector for the code. Also if i transition from scene 2 to any other scene it causes all my sprites in the midground to dissapear except my player(the colliders are still these, just not the sprites)

    scene 1 in my inspector

    position of my scene transition collider

    check the position of my objects – i have to place them roughly the coordinates of the scene transition collider – the start point thing doesn’t seem to affect anything even though ive moved it to a different position

    when i transition from scene2 – scene 2 (2-2) all my midground assets delete

    #12431
    Terence
    Keymaster

    Hi Niyam,

    Do you also have a SceneTransition component in your other scene? The start location for scene 2 can only be set in the SceneTransition component in that scene itself.

    For the objects disappearing in Scene 2, do they still show up in the Hierarchy? Or are they missing from the Hierarchy as well? If they are in the Hierarchy, it might just be that their Sorting Layer is below everything else, which is why they are not showing.

    #12438
    Niyam Shah
    Participant

    Hi
    so i fixed my hierachy issue and the midground sprites are now visible (my scene transition was too high on z axis)

    Also the fix for my scene transition was strange? when i had a looping transition from scene2 back to the start point of scene 2 it bugged my game and stopped scene 1 from transitioning to the startpoint of scene 2? rlly weird but it works now

    #12444
    Terence
    Keymaster

    Glad you got it to work! So you didn’t apply any fix for the scene transition? It just started working by itself?

    #12445
    Niyam Shah
    Participant

    so i have a transition from scene 1 to scene 2 and back from scene 2 to scene 1 and they work perfectly with the start point.
    But then i do a transition form scene 2 to scene 3 in the same way and for some reason the error occurs for these transitons???
    ive set the startpoint in inspector and added scene transition and start point to scene 3. My second scene transition collider for scene 2 has a second start point child game object (ive removed this in testing but nothing changes?) – for some reason my character will go to scene 3 but spawn in the coordinates of the scene transition collider of scene 2???? idky its happening again when i just fixed the isssue before?

    #12446
    Niyam Shah
    Participant

    also in reply to ur comment: i had a looping scene transition from scene 2 back round to the start point of scene 2

    for some reason that was bugging up my game

    #12448
    Niyam Shah
    Participant

    View post on imgur.com

    here you can see my scene_2 colliders (the one on the bottom right is my scene 3 transitioner)

    in scene 3 i should come from the top – ive temporarily moved my character to the rough position of where i spawn in when entering the collider – for reference

    #12449
    Terence
    Keymaster

    One thing that can be helpful for you is to temporarily print debug messages, to ensure that you have the correct scenes targeted:

        // Start is called before the first frame update
        private void Start()
        {
            Debug.Log("Scene transitioning from: " + GameManager.Instance.transitionedFromScene);
            Debug.Log("Scene transitioning to: " + transitioningTo);
            if (GameManager.Instance.transitionedFromScene == transitionTo)
            {
                Debug.Log("Scene transition object: " + startPoint.name);
                PlayerController.Instance.transform.position = startPoint.position;
            }
        }
    
    #12452
    Niyam Shah
    Participant

    So i added the debug logs

    the “scene transiton object” doesnt appear when i go from transition 2 to 3 but it happens when i go from 1 to 2 or 2 to 1

    View post on imgur.com

    im not sure whats different but can u check my stuff in the inspector?
    my code is clearly correct

    #12453
    Niyam Shah
    Participant

    ok so i found the issue???

    so whenever i make a transition i need a transition to get back?

    im not sure why but i needed my scene 3 scene transition to be set to go to scene 2? thats all i changed and now it works

    rlly weird but sure

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: