VenomSolo
(VenomSolo)
1
Hey guys!
I’m wondering what is the correct way to spawn actor of child class and get pointer to parent class.
.h
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gun)
class TSubclassOf<class ABaseWeapon> gunClass;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gun)
class ABaseWeapon * gun;
And here is .cpp
const FVector spawnLocation = GetMesh()->GetSocketLocation("RightHand");
const FRotator spawnRotation = GetMesh()->GetSocketRotation("RightHand");
const FActorSpawnParameters spawnParams;
gun = GetWorld()->SpawnActor<ABaseWeapon>(gunClass, spawnLocation, spawnRotation, spawnParams);
But I’m still getting exceptions. Any help?
Dune
(Dune)
2
What are the exceptions?
Is the ABaseWeapon header file included anywhere?
Also try
TSubclassOf<ABaseWeapon> gunClass;
– Without the class defines at the start.
VenomSolo
(VenomSolo)
3
I get exception 0xC0000005: access violation in:
template< class T >
T* SpawnActor( UClass* Class, FVector const& Location, FRotator const& Rotation, const FActorSpawnParameters& SpawnParameters = FActorSpawnParameters() )
{
return CastChecked<T>(SpawnActor(Class, &Location, &Rotation, SpawnParameters),ECastCheckedType::NullAllowed);
}
Header file is included.
First thing I would try is checking GetWorld is not returning nullptr. Probably worth checking that on gunClass too.,