hi
i call coroutine B() from first coroutine A()
in B(), i test 4 concurent positions of a gameObject Obj and would like to test for each position if obj is in collision with others objects : to test this, i have some other script with OnCollisionEnter () …
as OnCollisionEnter test rune once a frame, i tried to alternate each change of position with a call to WaitForEndOfFrame but it seems it appear this function do NOT wait for the end of frame and then collision fails
sorry … my question is : is it normal that function WaitForEndOfFrame DOT NOT wait for end of current frame when it is called from nested coroutines ( i call coroutine B() from first coroutine A() ) ?
Code looks like :
void Update() {
StartCoroutine(“A”);
}
IEnumerator A() {
…
StartCoroutine(“B”);
…
}
IEnumerator B() {
…
yield return new WaitForEndOfFrame(); / DO NO wait for end of frame
…
}
I honestly don’t know as I’ve never set up a set of calls like this, but it should work to wait till the end of whatever frame B is started in. Also what scenario are you wanting to do this? Update runs every frame and so you are starting a new coroutine every frame, thus you may not even notice if it’s waiting as you’re have a copy of A and B running every frame. You may be creating a ton of unneeded calls.
I know you tried to explain something above, but I really don’t understand what you are saying. You could just start a coroutine and have it loop, doing the yield within the loop and checking whatever you need it to check.
WaitForEndOfFrame is fine. Trouble is OnCollisionEnter doesn’t happen at the end of a frame.
This is wrong. OnCollisionEnter happens in FixedUpdate. Which can happen once, multiple times, or not at all in a frame frame. And if it happens, it happens at the start of a frame.