Create and spawn several actors in a constructor

Hello!

Spawning is probably the wrong word here but it’s the best I could figure out, anyway I’m looking to create a way where when I drag out one class/blueprint to the game world several actors are “spawned” and shown. The actors I want to spawn are chesstiles, so I need each tile to be individual. Currently I’m using SpawnActor to spawn the tiles in the BeginPlay() function but I would like them to be constantly visible instead of spawning when BeginPlay starts.

I’ve tried using NewObject() but it spat back a cast error, so I figured that was the wrong approach.

Grateful for any advice!

Hello, Tim0ntel

I am sorry to hear about your problem.

Please note that NewObject() should not be used for AActor-derived classes. The main point here is that AActors have a transform (Actor is the base class for an Object that can be placed or spawned in a level), whether UObjects don’t. Thus, their instantination is handled differently.

Another thing is that in general, when you want your Actors to be always visible, you may want to place them manually inside your level in the Editor.

Please also note that you can also spawn your Actors from PostInitializeComponents() method.
If you like to learn more about Actor Lifecyle in Unreal Engine 4, please go here:

Hope this helped!

Good luck!

I’m gonna take a look at it thanks!

Please note that you can also use OnConstruction() method. However, please note that it will be called every time you change a property of your Actor. In other words, if you put Component creation in there, it will be flushed and re-done after every property change. On the other hand, it is suitable for procedural content creation.