Crash after around a minute, TArray of actors

I have a third person template set up to test some stuff, what i’m trying to do is create a weapon switching system, it seemed to work at first, but after a minute or so, it crashes, in my .h file i have this :

UPROPERTY()
class AWeapon* CurrentWeapon;

UPROPERTY()
int32 WeaponIndex;

UFUNCTION()
void ChangeWeaponUp();

UFUNCTION()
void ChangeWeaponDown();

UPROPERTY()
TArray<class AWeapon*> Weapons;

UFUNCTION()
void AddToWeaponList(class AWeapon* Weapon);

Here is the code i added to .cpp file, i put it on pastebin, as the formatting looks terrible on here, and i’m unsure how to make it better. void AMyProjectCharacter::ChangeWeaponUp(){ WeaponIndex++; if (Weapons.Num - Pastebin.com

Everything else is the base template, and the weapons are added by a pickup handler that also spawns the weapons at runtime.

I can switch between weapons, and the old ones are destroyed, but then it just crashes…?

Can anyone see anything obviously wrong with the code that would cause the game to crash?.

void AMyProjectCharacter::AddToWeaponList(class AWeapon* Weapon)
You add a existing Weapon from the World to your Inventory. If that instance gets destroyed (I assume your Weapon Spawner does it) everytime you try to access it from your array you get a nullptr. All Functions you got there are affected and all can throw a access error.

I recommand using adding the UClass to the Array instead.

Okay so now i add weapons to the array like so:
Weapons.Add(Weapon->GetClass());
Changed the array to this :
TArray TSubclassOf class AWeapon Weapons; (Arrows don’t work)
And spawn like this:
CurrentWeapon = World->SpawnActor(Weapons[WeaponIndex], Location, Rotation, SpawnParams);

That seems to prevent the crash, which is certainly what i wanted.

But now none of the information about the object is retained, is there some way i can keep that information? in the weapon class i have editable properties and some getter functions to retrieve a name and whatnot, now name just returns as the class itself.

Never mind, i passed the TSubclassOf object from the pickup handler to the AddToWeaponsList function in the character class, then i can use :
*Weapons[i].GetDefaultObject()->GetName();
To access the BP class getter functions that i added.