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 :
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.