Run the update method and an another method simultaneously


I have a question is there a way how i can run a method at the same time as the update. Example in unity there is a function to start a coroutine is there something similar in playcanvas or javascript in general.

Thanks and sorry if it is a dumb but javascript is not my forte :smile:

A computer can only run one thing at any given time. But it can do many things inside a frame.

Maybe I don’t understand what your problem is, but it sounds to me like you simply want to call another function?

Co-routines (Generators in javascript) aren’t generally supported in most web browsers. So you can’t do a Unity style co-routine.

On the whole, Javascript in the browser is single-threaded so in your game, you get a sequence of update function calls in order to make perform actions.

It is possible to run code in a separate “Worker”. See Web Workers, but they don’t really fill the same niche as co-routines in Unity.

@Owen_Attard is simple async method with callback is not what you need?

Coroutines in Unity do not run in parallel. They run until you yield and then another coroutine continues etc. So if by ‘simultaneously’ you mean in the way Unity does coroutines then no there are no coroutines in PlayCanvas or Javascript at the moment. You can achieve the same result using regular functions and timers or callbacks.

1 Like