Does UnityEngine.CustomeYieldInstruction works in a seperate thread?

As we know coroutines works in the main thread and i read somewhere that by implementing customyieldinstruction you can wait for something to complete in a separate thread. Is this true? Will it not freeze or slows down my app??

Does CustomYieldInstruction work in a seperate thread?

No. It doesn’t

We know that any Unity API cannot be accessed from a seperate thread.

And CustomYieldInstruction is just another Unity API except the fact that you’re now yielding a custom event (loading an image) instead of an Unity event (an update cycle or fixed time).

As per the documentation, keepWaiting property (defined in your CustomYieldInstruction class) is queried each frame after Update and before LateUpdate call.

Although as @Bunny83 has pointed out, you can possibly do custom logic such as downloading the image, using your own thread, loading it into memory (through Resources.Load() for ex) can only be done using Unity’s main thread.

Same behaviour can also be achieved using WaitUntil or WaitWhile instructions. However if logic to yield is complex it’s good to use CustomYieldInstruction to make the code easy to read and maintain.

i have to load almost 100 images on my home screen but yield return freezes the app. Do you have any solution in mind ?

I just want to download high res images but don’t want the unity to freeze? Is there any solution? Will async/awaiy work?