multithreading possibilities

Hi,

so far I have implemented two different classes using a background thread, a FRunnable and a FNonAbandonableTask. The FRunnable works fine with my RTS map decomposition system (detecting the environment and converting the sensed data into a database for the pathfinder ensuring very fast access), only one thread is needed, and the main task is simply not to freeze the editor and the game for 10-15 seconds as before, when I used the game thread. But in a different case, it produced a heavy load on the game thread, resulting in long freezes, when I had to start 20-30 of my RTS unit pathfinders, so changed it to a FNonAbandonableTask, which seems to be a good choice. They are not very long processes (works only a bit slower when using purely the game thread), but many can be started within a frame.

So far so good, but I have 2 questions:

  1. Unfortunately, FRunnable cannot be used for further processing (the second part of the map decomposition system) where I call UGameplayStatics::GetAllActorsOfClass() because it uses actor iterator which applies a check() for the game thread, and results in halting. I have to read and write some pathfinder related data from RTS game actors, which data is definitely not used until the process is done, and nothing rendering and movement related touched.
    Would it be good to switch to FNonAbandonableTask, or use my own actor loop, or accessing actors is totally unsafe? (In the working FRunnable based solution I have a map actor that has two large ustructs which are processed fine.) Fortunately, the 2 processes are totally separated, and the second is much shorter, hard to sense the freeze when runs in the game thread, but it should handle many actors to modify the pathfinder data (trees, obstacles, buildings, units).

  2. Is there any other faster/safer multithreading option in UE4 I could use for the above mentioned purposes? Namely: a single thread solution for a long process; and a many thread per frame solution for shorter processes (basically A* searches).

I have found some forum threads and wiki tutorials, but the available docs are limited, and it is still not really clear when I should use which class, so I would be happy with some hints or short examples… :slight_smile:

Thanks.