How to spawn blueprint object from c++

Hello, everyone. Here is my problem: I created a c++ class floorCell then used this calss as a parent class for blueprint. add static mesh and a few other things. Also I have a gameMode c++ class which have spawn() function. So I want to spawn floorCells from this function. What should I do. If I just use SpawnActor with floorCell parameter it is of course spawned but without any mesh. Thank you.

You want to spawn the blueprint in c++ ? You need to import the blueprint class. Add a variable to your class, something like:

UPROPERTY( BlueprintReadWrite )
TSubclassOf<AFloorCell> FloorCellClass;

Then import the blueprint in the constructor:

static ConstructorHelpers::FObjectFinder<UClass> FloorCellClassFinder( TEXT( "Blueprint'/Game/YourProject/SomeFolder/YourBP.YourBP_C'" ) );
FloorCellClass = FloorCellClassFinder.Object;

You can get the reference by right clicking on your bp and doing ‘copy reference’. Note the _C near the end which is added on.

Then, in your spawn function, you do this:

AFloorCell* NewFloorCell = SpawnActor<AFloorCell>( FloorCellClass, SpawnParams );

This is a good answer, but I think in your spawn function you need to add “GetWorld()->” first, ie:

AFloorCell* NewFloorCell = GetWorld()->SpawnActor<AFloorCell>( FloorCellClass, SpawnParams );