Hello guys, I am having a problem with this function, it works well for all cases except in one specific case where it can’t pass through the yield line. Trying to debug the problem I used the following Debug.Log prints:
When running the game in this specific case it prints the ‘AOEHAOEH’ and the ‘2AOEHAOEH’ but it never goes to the ‘3AOEHAOEH’.
The object is never destroyed ( the doDeathAction just reloads the scene and it comer after the yield);
There are no endless loops in the “DidDie” functions from the object;
The object and its scripts are always active;
In the other cases (like being called from OnTriggerEnter) it works well, it just one case that this bug appears;
This case is when I call the function “killPlayer” from an other script in its update function. I use the “isDead” boolean to avoid to call this function everyFrame, it is called only one time.
The object that have this bugged script is the player. After calling this function in this specific case I can keep controlling the player since it never goes to the “doDeathAction”, also it doesn’t show any error message. Can someone give me a light? Thanks you.
Hmm, I tested your code here and it’s working fine. Are you sure that you’re calling killPlayer in a singleFrame? Also, make sure to don’t call in multiple places…
I doubt this is the problem since you’re checking Time.time, but make sure you don’t have Time.timeScale set to zero, since WaitForSeconds uses game time.
I am calling killPlayer from a single place, and even if I wasn’t doing this the yield can’t be called more than 2 times because of that IF surrounding it;
The time scale is 1 here;
It is not like it doesn’t work, this function works, the only case where it doesn’t work is when I call it from an Update function from another script BUT I check if the player is alive before calling it, so it is called only one time.
EDIT: Halp
EDIT2: If I comment the yield (1.3) line it works well in ALL cases, so I am sure that the problem is in that line. It is like it stop counting the time when you reach that line.
It is just a “function indirection” so it doesn’t make sense for me, but if it is working I am happy. Maybe it is time to update my Unity or report a new bug
Removing the SendMessage didn’t change anything, the problem persists if I use only one function (without the killPlayer2).
Also I tried to use the StartCoroutine inside the Update but it didn’t change anything. I read somewhere that there is no need to use this funcion when using UnityScript.