I’m currently setting up and executing an FRunnableThread. The thread is spawned by hitting a key in Blueprint, and which calls a method on an object (which extends AActor) that was placed in editor. This actor works as a message server for a limited number of other actors; it waits to receive information from outside UE4, checks what actor it should transmit that information to, and transmits it.
However, on top of this functionality, I’d like to trigger a blueprint event on the receiving actor when transmitting a message to it, so my team’s level designers can update their HUD and animate models accordingly.
Naturally, there are workarounds (eg, mark as dirty + poll to check if dirty & fire a latent event from within Tick(), which runs in a thread permitting BP event firing), but I’ve got the feeling I’m just not calling the event at the right time / from the right thread, or perhaps am not setting some actor flags necessary to permit the event firing from a thread.
I’ve created many events before from Blueprint, and it’s very straightforward. So, knowing how to create an event isn’t the issue - rather, I’d like to know the best way to make an event fire when called from an FRunnableThread.
Hmm, never mind me - after some further troubleshooting, it appears that the server’s client actors were being duplicated Will post back to confirm whether avoiding this duplication fixes the problem.
My issue was that I was getting a reference to an in-editor object during PIE, by mistakenly using TObjectIterator<> to iterate through all instances of my custom actor class. Since my code had a reference to an in-editor object, I wasn’t getting any errors when trying to invoke Blueprint events for it.
I would normally have fixed this issue by instead using TActorIterator<>, which iterates only over PIE objects when playtesting in the editor. However, since that method requires use of GetWorld(), like such:
TActorIterator actorIterator(GetWorld());
… it’s not usable outside of the main game thread. Since my FRunnableThread code executes outside of the main game thread, I had to make a different solution.
In the end, I settled for managing a TArray<> of instances of my custom actor class. That TArray is stored as a static member of my custom actor class. This way, my server class can access that static member to collect references to the custom actors as needed.