SpawnActor failed because no class was specified - When trying to spawn second actor in array

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.

Check again if all weapons are in DefaultInventoryClasses. How exactly are you checking its content?

Hey thanks for the reply!

I removed the player in the scene and placed a new copy of them in there and it now works fine. Im confused as to why this has solved the issue.
If I remeber correctly when I first created the player in the scene I had only 1 weapon assigned on the player blueprint.

So updating the player blueprint did not update the one in the scene?
However the player that was originally in the scene was reporting that he had two objects in his weapon array when I was logging it so this just confuses me more.

At least it works now, but I would like to know as to why.

Only because an array has n elements, it doesn’t mean it has n valid elements:

1.png

Yeah that makes sense, thanks for the example!