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
- This topic has 14 replies, 2 voices, and was last updated 1 year ago by Niyam Shah.
-
AuthorPosts
-
December 2, 2023 at 5:58 pm #12416December 2, 2023 at 6:13 pm #12418::
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() { } }
December 2, 2023 at 6:17 pm #12419::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)
December 2, 2023 at 6:22 pm #12422::ive tried to wend you images via imgur but they arent sending even though i followed the tutorial many times
December 3, 2023 at 9:16 am #12429December 3, 2023 at 12:50 pm #12417::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
December 3, 2023 at 1:14 pm #12431::Hi Niyam,
Do you also have a
SceneTransition
component in your other scene? The start location for scene 2 can only be set in theSceneTransition
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.
December 3, 2023 at 10:26 pm #12438::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
December 3, 2023 at 11:33 pm #12444::Glad you got it to work! So you didn’t apply any fix for the scene transition? It just started working by itself?
December 3, 2023 at 11:34 pm #12445::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?
December 3, 2023 at 11:35 pm #12446::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
December 3, 2023 at 11:45 pm #12448::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
December 3, 2023 at 11:52 pm #12449::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; } }
December 4, 2023 at 12:00 am #12452::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
December 4, 2023 at 12:03 am #12453::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
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: