Hey guys, new to Unreal from Unity so i’m still trying to get my head around a few things.
I’m trying to spawn guns on the player, the first gun in the array is spawned fine but the second causes the ‘SpawnActor failed’ warning message.
I’ve verified that there are two guns in the array through logs, so im confused as to why it fails to spawn the second gun.
My guns are all derive from the same ‘Gun’ class, could this be the problem with the code I have?
I’ve been trying to emulate the ShooterGame example and the only diffrence I can see is that the guns there both have their own classes but are still derived from the same gun class.
Player.h
UPROPERTY(EditDefaultsOnly, Category = Inventory)
TArray<TSubclassOf<AActor>> DefaultInventoryClasses;
Player.cpp
int32 NumWeaponClasses = DefaultInventoryClasses.Num();
for (int32 i = 0; i < NumWeaponClasses; i++)
{
FActorSpawnParameters SpawnInfo;
SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
AGun* NewWeapon = GetWorld()->SpawnActor<AGun>(DefaultInventoryClasses*, SpawnInfo);
AddWeapon(NewWeapon);
}
Any help or direction would be greatly appreciated.
