I am modding an Unity (2020.3.26f) sport that makes use of SceneManager.LoadSceneAsync
when the participant enters a zone, and UnloadSceneAsync
once they go away.
The scene incorporates GameObject
s of sources that may be picked up. When the participant picks them up, their distinctive id is added to a HashSet
. Because the scene could be unloaded and reloaded by reentering it, upon reenter, a MonoBehaviour
on these useful resource GameObject
s must be triggered, which checks the HashSet
and hides the simply loaded GameObject
. This works, however not reliably for some cause. (The precise code is extra concerned, however that is not related right here).
class OnAfterLoadScene : MonoBehaviour
{
int objectId;
void Begin() {
Debug.Log("Perhaps hiding " + objectId);
if (GlobalState.alreadyPicked.Accommodates(objectId)) {
gameObject.SetActive(false);
}
}
}
The issue is, this Begin()
typically would not execute in any respect, regardless of how lengthy the participant waits. The item is sitting there nonetheless seen. Generally a number of load and unload cycle has to occur earlier than the Begin
methodology will get truly executed.
This occurs in lots of circumstances with the vanilla sport. My mod comes into this by triggering the scene loading forward of time, with out the participant triggering it by way of the default means (getting into a collider field).
What could possibly be the issue and/or how ought to I debug this downside additional?