How to instantiate a blueprint object from a C++ script?

Unfortunately there’s no such thing. When creating objects in Unreal’s framework, parameterized constructors are basically a no-go. This goes for both calls to SpawnActor and NewObject.
The result is that you’ll have to write ‘Init’ functions of some sort that are called after the object is created.

This can be a real problem for Actors since you may need it initialized before BeginPlay happens, which normally happens before you get control back from SpawnActor. Fortunately there’s a solution to this with SpawnActorDeferred. It’s basically only part of the SpawnActor call that requires you to then call SpawningFinished sometime later. BeginPlay is then called from SpawningFinished. This allows you to do your initialization between the Spawn & SpawnFinished calls.

Also on the topic of constructors, you’ll find that any structure using the USTRUCT macro is required to have a default constructor that can be called with no parameters. You can have others in addition to that, but you can’t have only parameter requiring constructors.

1 Like