How to spawn blueprint actor that is inheriting from C++ class?

I have a AEnemyPartBase class, I created blueprint that inheriting from this class

I want to spawn such blueprints from C++

I have provided the actor blueprint to the C++ like this

UPROPERTY(EditDefaultsOnly, Category = "Detach Parts")
TSubclassOf<AEnemyPartBase> LeftArm;

LeftArm - is the blueprint actor reference that is inheriting from the AEnemyPartBase class.

I’ve tried different ways of spawning it but neither did work

Is this even possible? Or I must create a C++ class in order to be able to spawn it from C++?

1 Like

No, it’s right. That’s how I do it, at least:

.h:

UPROPERTY(EditEnywhere)
TSubclassOf<AMyActor> MyActorClass; // Set reference in the BP

.cpp:

FTransform NewTransform; // Set Transform here
GetWorld()->SpawnActor<AMyActor>(MyActorClass, NewTransform);
1 Like

Somehow the blueprint lost the LeftArm value - the issue occured because it was unset.

It’s one of those things that are get lost after editor restart until you trigger live update from the IDE.
It’s wont be lost only after full rebuild from the IDE

It’s working now, I’m using the same approach as you described.

Yeah, happens all the time. You set the reference, even save the blueprint, but then the engine crashed because you left a null pointer somewhere else, and when it’s restarted the reference isn’t there, but you know that you’ve set it and saved it. So it get’s a bit confusing at times =)

1 Like