How to spawn blueprint actor from editor

Hi,

So in my header i have

UPROPERTY(EditAnywhere)
UObject* objectToSpawn;

which takes the blueprint
And this

UPROPERTY(EditAnywhere)
AActor* objectSpawnTarget;

to take the target position vector.

So now in my .cpp …
i am unsure how to make it spawn on targeted location… any ideas?

Just follow the documentation :wink: (and google it at least once…)

Here https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Actors/Spawning/

Good luck !
Best regards.

Hi ,

I now have this in my header

UPROPERTY(EditAnywhere, Category = "Our Spawning Object")
TSubclassOf<ASpawner> ourSpawnObject;

and this in my .cpp

//create spawn params
FActorSpawnParameters spawnParams;
//who did the spawn? THIS controller did it
spawnParams.Owner = this;
//instigator to default
spawnParams.Instigator = Instigator;
ASpawner* ourNewObject = GetWorld()->SpawnActor<ASpawner>(ourSpawnObject,objectLocation, FRotator::ZeroRotator, spawnParams);

Currently it is not spawning my blueprint… but i suspect im getting closer…
Its probably is because of the subclass i defined ASpawner
TSubclassOf ourSpawnObject;

The problem is how does it know what class type it should be ? and even if i got the class type, how do you actually pass it in < > ??

I don’t want to hardcode anything … as i actually want to allow the editor to be able to spawn any blue print actor i pass to it.

Hi All,

So finally… i may have found what i need.
I added this to my header

UPROPERTY(EditAnywhere, Category = "Our Spawning Object")
TSubclassOf<UObject> ourSpawnObject;

and used this in my .cpp

//create spawn params
FActorSpawnParameters spawnParams;
//who did the spawn? THIS controller did it
spawnParams.Owner = this;
//instigator to default
spawnParams.Instigator = Instigator;
UObject* ourNewObject = GetWorld()->SpawnActor<UObject>(ourSpawnObject,objectLocation, FRotator::ZeroRotator, spawnParams);

The whole time i wasn’t sure what to put in < > as all the code out there kept pointing me to pointing to a child object of the class , or the class itself. So just by luck i just tried UObject as i remembered Blueprints are UObjects somewhere.

Anyways , if you guys have an easier solution, or spot something i did horribly wrong please let me know!