I am trying to spawn a static mesh actor into the editor from a C++ plugin that I am creating. The call worked great when I was prototyping in a slate UI control callback, but it is crashing now that I moved the logic to a thread in the plugin. Unreal is crashing when I make the following call from a thread in plugin.
After debugging this in VS, it broke on the following line. check(IsInGameThread());
I am definitely NOT in the game thread. I have read the Multi Threading How To in the Unreal wiki. It definitely warns you not to manipulate UObjects from other threads.
So my question is: how do you accomplish spawning/destroying actors from other threads? There must be a way to do this. This information would be extremely useful to add to the Multi Threading How To wiki.
Thanks for the reply. My thread is waiting on a FSocket->>Recv() call to receive asynchronous messages from a server. Some message require that I manipulate/spawn UObjects
Hmm, you probably don’t need a separate thread for it.
I’d handle the socket in the game thread by registering a tick function, that checks whether there’s any data to be received and only then calling Recv.
That’s also how the game itself handles multiplayer internally.
Invert interaction make UObject interact with your socket data that you received left in memoery by other thread, maybe on Tick()? OR some other event that needs that data
That will not work in call cases. If the data he is receiving is data which, say moves the character forward, then movement will be tied to the game tick. Since Tick is called once per frame, you are essentially binding your data processing rate to that of the frame rate.
Is there an alternative? What if I want to consume data as soon as it arrives, and not wait for the Tick?