Forum begins after the advertisement:


[part 6] death breaks GameManager

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [part 6] death breaks GameManager

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

    Its saying my GameManager game object is inactive? Ive added debug logs to my coroutine and the entire Respawned() void plays and it was working before but suddenly stopped? Now the button for respawning doesnt play(ive set it as game manager prefab and respawned void)

    ive also set GameManager.SetActive(true); everywhere but ti doesnt seem to help

    strange how it just happened when i didnt change anything??

    on my game manager code – the debug logs print all of them except for 1(for obvious reason)

    ive noticed my respawn point wont change to my platformrespawn point in the inspector when running – it was working before :(

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    using UnityEngine.UI;
    
    public class GameManager : MonoBehaviour
    {
        public string transitionedFromScene;
    
        [SerializeField] public Vector2 platformingRespawnPoint;
        [SerializeField] public Vector2 respawnPoint;
        [SerializeField] SavePoint savePoint;
    
        public static GameManager Instance { get; private set; }
    
        private void Awake()
        {
            if(Instance != null && Instance != this)
            {
                gameObject.SetActive(true);
            }
            else
            {
                Instance = this;
            }
            DontDestroyOnLoad(gameObject);
            savePoint = FindObjectOfType<SavePoint>();
        }
    
        public void RespawnPlayer()
        {
            if (savePoint != null)
            {
                if (savePoint.interacted)
                {
                    respawnPoint = savePoint.transform.position;
                }
                else
                {
                    respawnPoint = platformingRespawnPoint;
                    Debug.Log("repsawn set");
                }
            }
            else
            {
                respawnPoint = platformingRespawnPoint;
                Debug.Log("repsawn set2");
            }
            PlayerController.Instance.transform.position = respawnPoint;
            Debug.Log("repsawn set3");
            StartCoroutine(UIManager.Instance.DeactiveDeathScreen());
            Debug.Log("repsawn set4");
            PlayerController.Instance.Respawned();
            Debug.Log("repsawn set5");
        }
    }
    #12627
    #12629
    Niyam Shah
    Participant

    also for reference: i respawn as normal when touching spikes?

    also the button isnt interactive in scenes 2 or 3 despite me setting it to interactive and applying aall things in the prefab

    #12637
    Terence
    Keymaster

    Hi niyam,

    We are going to have to do a video call with you to be able to fix this. I can get you in touch with Matias or Kiefer to help you with this issue over video, but there will be a fee to this. Let me know if you are open to this.

    #12639
    Niyam Shah
    Participant

    hi
    i dont see why we would need to video call over this??
    r u sure theres no other way we can do this?? like sending info through the forum like normal..

    #12641
    Terence
    Keymaster

    Hi niyam, I don’t have enough information to offer you a solution, and the easiest way is to do it through a video call, because we can find and test things very quickly.

    Otherwise, I will need you to find which Coroutine the error is referring to. Because I don’t see any Coroutines on the Game Manager script.

    #12643
    Niyam Shah
    Participant

    It’s referring to the UI managers scene fader coroutine. I’ve added debuglog.actives and it’s returning false in the respawn function but true if I place it anywhere else

    #12644
    Niyam Shah
    Participant

    This causes the respawn point to not set to the platform respawn point or save point in game manager inspector

    Therefore the respawn button won’t work
    Thofht I’m not sure why it suddenly isn’t working

    #12648
    Niyam Shah
    Participant

    ok so ive discovered:

    my gamemanager is active during the awake function of the script but becomes inactive during the respawn player script – i have no idea why as i dont have a gameObject.SetActive(false) in it?? ive set gameObject.SetActive(true) in the function everywhere but it still returns a false value

    #12657
    Terence
    Keymaster

    my gamemanager is active during the awake function of the script but becomes inactive during the respawn player script – i have no idea why as i dont have a gameObject.SetActive(false) in it?? ive set gameObject.SetActive(true) in the function everywhere but it still returns a false value

    It’s difficult to pinpoint the reason for this over the forums. There can be many causes for this, which is why I asked for the video call, but one thing you can check is you can see if there is more than 1 GameManager on the Scene. Type in t:GameManager on the Scene and it will show you all the GameManagers on the scene.

    #12663
    Niyam Shah
    Participant

    yep theres only 1 game manager so its not that..:
    maybe its my code? my game manager deactivates in the respawn function but stays active in the awake function? however i dont see why this would happen in my code

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    using UnityEngine.UI;
    
    public class GameManager : MonoBehaviour
    {
        public string transitionedFromScene;
    
        public Vector2 platformingRespawnPoints;
        public Vector2 respawnPoints;
        [SerializeField] SavePoint savePoint;
    
        public static GameManager Instance { get; private set; }
        private void Awake()
        {
            if(Instance != null && Instance != this)
            {
                Destroy(gameObject);
            }
            else
            {
                Instance = this;
            }
            DontDestroyOnLoad(gameObject);
            savePoint = FindObjectOfType<SavePoint>();
            Debug.Log("Active? " + gameObject.activeInHierarchy);
    
    
        }
    
        public void PlayerRespawn()
        {
            DontDestroyOnLoad(gameObject);
            savePoint = FindObjectOfType<SavePoint>();
            if (savePoint != null)
            {
                if (savePoint.interacted)
                {
                    respawnPoints = savePoint.transform.position;
                }
                else
                {
                    respawnPoints = platformingRespawnPoints;
                    Debug.Log("repsawn set");
                }
            }
            else
            {
                respawnPoints = platformingRespawnPoints;
            }
            PlayerController.Instance.transform.position = respawnPoints;
            StartCoroutine(UIManager.Instance.DeactiveDeathScreen());
            PlayerController.Instance.Respawned();
        }
    
    
    }
    #12664
    Terence
    Keymaster

    You will need to figure this out on your own, because I think the issue is related to your scene setup. Not your code.

    #12665
    Niyam Shah
    Participant

    yes i see. do u think its alr to delete my game manager prefab and remake it along with the death mechanic

    or would deleting the game manager now destroy my game or smt?

    #12666
    Niyam Shah
    Participant

    ok so it seems ive found a fix. Despite the GameManager prefab being the same as the GameManager game object, if i set the OnClick() button function to the prefab; it wont work, i hav to manually drrag the gamemanager gameobject of that scene into there. IVe tried remaking the prefab with this new gamemanager but same results.

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

Go to Login Page →


Advertisement below: