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
- This topic has 13 replies, 2 voices, and was last updated 12 months ago by Niyam Shah.
-
AuthorPosts
-
December 13, 2023 at 4:37 am #12625::
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"); } }
December 13, 2023 at 4:37 am #12627December 13, 2023 at 8:03 am #12629::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
December 13, 2023 at 12:33 pm #12637::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.
December 13, 2023 at 2:42 pm #12639::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..
December 13, 2023 at 6:55 pm #12641::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.
December 13, 2023 at 7:42 pm #12643::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
December 13, 2023 at 7:43 pm #12644::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
December 14, 2023 at 5:22 am #12648::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
December 14, 2023 at 1:02 pm #12657::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.December 14, 2023 at 4:42 pm #12663::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(); } }
December 14, 2023 at 4:45 pm #12664::You will need to figure this out on your own, because I think the issue is related to your scene setup. Not your code.
December 14, 2023 at 4:48 pm #12665::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?
December 14, 2023 at 5:39 pm #12666::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.
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: