Hi! I’ve been doing this C++ tutorial (https://docs.unrealengine.com/latest/INT/Videos/PLZlv_N0_O1gYup-gvJtMsgJqnEB_dGiM4/qZHMf2WqjSM/index.html). I have a problem to spawn proper actor that is derived from my Pickup class (Pickup class is C++ class) I have bluprint class called BatteryPickup_BP that is derived from my C++ class (APickup). I have setted static mesh component in blueprint and If I drag that bluprint to the level, the right actor is showing up and works fine. But when I try to spawn that actor in my C++ code nothing shows up. I added console log output to spawn function and I checked that it is called. I have one spawn volume that should spawn blueprint actors. I’ve set TSubclassOf<class APickup> class (in spawning volume) in editor to BatteryPickup_BP so it should spawn my blueprint actors. There are actors being spawened to level from my spawning volume but their class is APickup instead of BatteryPickup_BP. What am I doing wrong or is this suppose to be worked like this?
Here is how I define what to spawn in spawn volume actor:
UPROPERTY(EditAnywhere, Category = "Spawning")
TSubclassOf<class APickup> WhatToSpawn;
Here is my spawn function:
void ASpawnVolume::SpawnPickup()
{
if (WhatToSpawn != NULL)
{
UWorld* const World = GetWorld();
if (World)
{
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.Instigator = Instigator;
FVector SpawnLocation = GetRandomPointInVolume();
FRotator SpawnRotation;
SpawnRotation.Yaw = FMath::FRand() * 360.0f;
SpawnRotation.Pitch = FMath::FRand() * 360.0f;
SpawnRotation.Roll = FMath::FRand() * 360.0f;
APickup* const SpawnedPickup = World->SpawnActor<APickup>(WhatToSpawn, SpawnLocation, SpawnRotation, SpawnParams); // <------------ Is this the right way to do it?
SpawnDelay = FMath::FRandRange(SpawnDelayRangeLow, SpawnDelayRangeHigh);
GetWorldTimerManager().SetTimer(SpawnTimer, this, &ASpawnVolume::SpawnPickup, SpawnDelay, false);
}
}
}
I spawn actor using World object’s SpawnActor function that should spawn my blueprint actor. I’ve set WhatToSpawn in editor earlier but for some reason only APickup is being spawned but not the bluprint class that is derived from APickup.
Any thoughts?