Forum begins after the advertisement:


[Part12] Regarding some operational issues in the article

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part12] Regarding some operational issues in the article

Viewing 15 posts - 31 through 45 (of 48 total)
  • Author
    Posts
  • #16974
    MI NI
    Level 15
    Bronze Supporter (Patron)
    Helpful?
    Up
    0
    ::

    I found that if the player dies, my monster will move forward uncontrollably, or it will be completely stuck and will not move, and the player cannot use healing health after death.

    #16976
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    I will be improving on the health / mana UI and mechanics in the next part. Doing a stream on Tuesday.

    EDIT: Regarding the healing, it should still be working. But you will need to hit some enemies to restore your mana first.

    #16993
    MI NI
    Level 15
    Bronze Supporter (Patron)
    Helpful?
    Up
    0
    ::

    At the end of the video, I attacked monsters after resurrecting until I fully restored Mana. I jumped on the platform and tried to heal health, but it had no effect. Other functions could still be used normally.

    #16994
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Can you share your project over Google Drive? I’ll help you have a look.

    #16996
    MI NI
    Level 15
    Bronze Supporter (Patron)
    Helpful?
    Up
    0
    ::

    I tried to email you the cloud URL of the project, but it couldn’t be sent. Which email address should I send it to you from?

    #17004
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    I reached out to you via email. You can send me your project there.

    #17006
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    @mini, I found your issue. It’s not a problem with your healing. Your UI is not updating after you reset your character’s health back to 100 after respawn. So you are unable to heal because you are actually at max health.

    Only after you get hit once by the enemy, the healthbar updates and everything will function normally afterwards.

    View post on imgur.com

    Make sure you update your healthbar when you respawn the player.

    #17009
    MI NI
    Level 15
    Bronze Supporter (Patron)
    Helpful?
    Up
    0
    ::

    Thanks for your tip, I corrected him. But some problems occurred when I was testing other functions. I found that when I switched scenes, blackFade would not disappear and an error message would be generated. I didn’t know what to do.

    #17010
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Can you post your code that is causing the error here and specify the line where the MissingReferenceException is? The AI will be better suited to help you here.

    Do a print(name) above the group.alpha line (the one with the error) as well and tell me what the output is as well.

    #17011
    MI NI
    Level 15
    Bronze Supporter (Patron)
    Helpful?
    Up
    0
    ::
    MissingReferenceException: The object of type 'CanvasGroup' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    UIScreen+<Fade>d__24.MoveNext () (at Assets/Script/UI/UIScreen.cs:180)
    UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <3b24cc7fa9794ed8ab04312c53e6dedd>:0)
        protected virtual IEnumerator Fade(float duration, int direction = 1)
        {
            WaitForSecondsRealtime w = new WaitForSecondsRealtime(updateFrequency);
    
            // Don't play as long as another animation is playing on this.
            while (isAnimating) yield return w;
    
            isAnimating = true;
            float currentDuration = duration;
    
            group.alpha = direction > 0 ? 0 : originalAlpha;
            gameObject.SetActive(true);
            while (currentDuration > 0)
            {
                yield return w;
                float timeScale = GetTimeScale();
                if (timeScale <= 0) continue;
                currentDuration -= w.waitTime * timeScale;
                float ratio = currentDuration / duration;
                print(name);
                <strong>group.alpha = (direction > 0 ? 1f - ratio : ratio) * originalAlpha;</strong>
            }
    
            group.alpha = direction > 0 ? originalAlpha : 0;
    
            if (direction < 0) gameObject.SetActive(false);
    
            isAnimating = false;
        }
    View post on imgur.com
    #17012
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::
    MissingReferenceException: The object of type 'CanvasGroup' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    UIScreen+<Fade>d__24.MoveNext () (at Assets/Script/UI/UIScreen.cs:180)
    UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <3b24cc7fa9794ed8ab04312c53e6dedd>:0)
        protected virtual IEnumerator Fade(float duration, int direction = 1)
        {
            WaitForSecondsRealtime w = new WaitForSecondsRealtime(updateFrequency);
    
            // Don't play as long as another animation is playing on this.
            while (isAnimating) yield return w;
    
            isAnimating = true;
            float currentDuration = duration;
    
            group.alpha = direction > 0 ? 0 : originalAlpha;
            gameObject.SetActive(true);
            while (currentDuration > 0)
            {
                yield return w;
                float timeScale = GetTimeScale();
                if (timeScale <= 0) continue;
                currentDuration -= w.waitTime * timeScale;
                float ratio = currentDuration / duration;
                group.alpha = (direction > 0 ? 1f - ratio : ratio) * originalAlpha;
            }
    
            group.alpha = direction > 0 ? originalAlpha : 0;
    
            if (direction < 0) gameObject.SetActive(false);
    
            isAnimating = false;
        }
    View post on imgur.com

    @Ser.Apustaja, the line above group.alpha = (direction > 0 ? 1f - ratio : ratio) * originalAlpha; is giving a missing reference exception as shown above. Any chance you can give an indication as to why? Or what we should look at?

    #17014
    Ser Apustaja
    Level 1
    AI Assistant
    (BETA)
    Helpful?
    Up
    0
    ::

    The MissingReferenceException you’re encountering indicates that the CanvasGroup object referenced by group has been destroyed, but your code is still trying to access it. This can happen if the object that the CanvasGroup component is attached to is destroyed before the coroutine completes.

    Here are a few suggestions to help you resolve this issue:

    1. Check if group is null before accessing it: You can add a null check before you try to access the alpha property of the group. This will help prevent the exception from being thrown if the CanvasGroup has been destroyed.

      if (group == null) yield break; // Exit the coroutine if group is null

      You can place this check at the beginning of your Fade coroutine.

    2. Ensure the GameObject is not destroyed prematurely: Review your code to ensure that the GameObject that holds the CanvasGroup component is not being destroyed before the coroutine finishes. If you are destroying the GameObject during the fade process, you may want to rethink your logic to ensure it remains alive for the duration of the fade.

    3. Use a try-catch block: If you want to handle the exception gracefully, you can wrap the code that accesses group.alpha in a try-catch block. However, this is more of a workaround and not a best practice for handling such issues.

      try
      {
          group.alpha = (direction > 0 ? 1f - ratio : ratio) * originalAlpha;
      }
      catch (MissingReferenceException)
      {
          yield break; // Exit the coroutine if an exception is caught
      }
    4. Debugging: Add debugging logs to check if group is becoming null at any point. This can help you identify where the destruction is occurring.

      Debug.Log($"Current group: {group}");
    5. Check the flow of your game logic: Make sure that there are no other scripts or game events that might be destroying the GameObject or the CanvasGroup while the fade coroutine is still running.

    By implementing these suggestions, you should be able to address the MissingReferenceException you’re encountering.

    #17019
    MI NI
    Level 15
    Bronze Supporter (Patron)
    Helpful?
    Up
    0
    ::

    I tried the above suggestions but I still don’t understand what the problem is. Is there any step I am missing on Unity that causes this problem?

    #17020
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Check the action assigned to your Quit to Main Menu button. Make sure that you are using LoadScene from the UI Manager instead of the Pause Menu, because if the Pause Menu gets disabled the switching of scenes stops.

    #17022
    MI NI
    Level 15
    Bronze Supporter (Patron)
    Helpful?
    Up
    0
    ::

    Yes, my QuitToMainMenu uses UIManager’s LoadScene, but my problem is that the Fader (Temp) will not be deleted when I switch scenes, but the player can still move freely, including using the pause menu, but the screen will be black. (Fader(Temp))

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

Go to Login Page →


Advertisement below: