x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Spawn Actors from Plugin Threads

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.

AStaticMeshActor *actor = Cast(GEditor->GetEditorWorldContext().World()->SpawnActor(AStaticMeshActor::StaticClass()));

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 help! Dan

Product Version: UE 4.10
Tags:
more ▼

asked Mar 20 '16 at 06:45 AM in C++ Programming

avatar image

dan.montz
6 1 2 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

Don't want to break the bubble, but UE4 gameplay is essentially single threaded. Anything that touches UObjects must happen in the game thread.

What exactly is your plugin doing that makes you think that it will benefit from multithreading?

more ▼

answered Mar 20 '16 at 02:44 PM

avatar image

MiKom
535 17 10 39

avatar image dan.montz Mar 20 '16 at 04:40 PM

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

avatar image MiKom Mar 20 '16 at 07:24 PM

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.

avatar image rich2020 Jul 27 '16 at 10:57 AM

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?

avatar image Shadowriver Mar 20 '16 at 07:31 PM

One note, not complitly single threaded, tick manager has multithread mode which separates tick computations to diffrent worker threads

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Mar 20 '16 at 07:27 PM

avatar image

Shadowriver
37.2k 936 172 1116

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Thanks for all of the responses. I'll try these suggestions and post my solution for the next guy.

more ▼

answered Mar 21 '16 at 05:08 PM

avatar image

dan.montz
6 1 2 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question