Spawn actor using Async task

Hello, I’m was just wondering if it was possible to use a Async tasks to spawn actors, and if so, how I would go about it. I know that you cannot spawn or delete assets on separate threads from the game thread, but I’m not sure if you can do this with Async tasks.

1 Like

I use Async tasks to do various things like spawn particles(which has an allocation), play sounds, and other such simple tasks. The basic UObject allocation is thread safe, but I think the problem you’ll run into is that the Actor you are trying to instantiate may not be threadsafe itself (e.g. It makes assumptions that its on the game thread and is running synchronously and not during some other task like Physics update or such).

If the actor is very simple (directly inherits from AActor and nothing else), I think you’ll probably be fine. I wouldn’t try to instantiate something like ACharacter or APawn on an Async Task (if you wanted something like that, I would just preallocate X of them on start up and re-use those X over and over).

In short, the basics are threadsafe, but that doesn’t mean an Actor itself is. As for creating it, you use the same methods: CreateObject / SpawnActor