Forum begins after the advertisement:


[Part 5] Article Changes, Common Issues & Bugfixes

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 5] Article Changes, Common Issues & Bugfixes

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #14602
    Joseph Tang
    Moderator

    This is an update post to summarize the changes made to the content of the Metroidvania series.
    Additionally, this post is to compile and go through some common issues that viewers and readers may face when following the Metroidvania series, as well as some solutions that may fix or solve the issues.

    Some solutions given will also be under the assumptions that the code for the mechanic is 1:1 for the relevant part.

    In this post, we will go through
    [Part 5]

      *Article Changes*

    • 1. SceneFader NullReferenceException Error
    • 2. Player hit while in scene transition stops cutscene
    • *Common Issues*

    • 3. Errors after transitioning scenes.


    [Part 5] Level Design and Lighting

    Article Changes

    1. SceneFader NullReferenceException Error

    [Caused by the SceneTransition script firing before the SceneFader is initialised.]

    • In SceneFader.cs script, change Start() to Awake() while leaving the code fadeOutUIImage = GetComponent<Image>(); the same.
        private void Start Awake()
        {
            fadeOutUIImage = GetComponent();
        }

    2. Player hit while in scene transition stops cutscene

    [Caused by inefficient code that does not prevent player from taking damage while in cutscene]

    • In PlayerController.cs WalkIntoNewScene(), set pState.invincibility to true in the first line, and set to false in the last.
    • Then, add a line in FlashWhileInvincible() to prevent the player from flashing while pState.cutscene is true.
    • Finally, in SceneTransition.cs OnTriggerEnter2D(), set the player’s pState.invincible to true before loading scene.

    PlayerController.cs

        public IEnumerator WalkIntoNewScene(Vector2 _exitDir, float _delay)
        {
            pstate.invincible = true;
    
            //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;
        }
    
        void FlashWhileInvincible()
        {
            if (pState.invincible && !pState.cutscene)
            {
                if(Time.timeScale > 0.2 && canFlash)
                {
                    StartCoroutine(Flash());
                }
            }
            else
            {
                sr.enabled = true;
            }
        }

    SceneTransition.cs

        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));
            }
        }

    Common Issues

    3. Errors after transitioning scenes.

    [There are multiple problems that can arise from this, some listed here, that can be solved by a note found in the Forum Post:]

    • 1. Mana isn’t being reset
    • 2. Invincibility and time stop is non-functional
    • 3. Hearts healed to full

    Make sure that there is only one scene containing your Prefabs with singleton scripts such as the Player and Canvas. Entering a scene with a second singleton instance will cause NullReferenceException errors as scripts cannot differentiate or single out one script instance from multiple.



    That will be all for Part 5.
    Hopefully this can help you on any issues you may have. However, if you find that your issues weren’t addressed or is a unique circumstance, you can submit a forum post to go into detail on your problem for further assistance.

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: