Tarray Break

void AHermesCharacter::PickUp(TSubclassOf spawn)
{
AWeapon* point = GetWorld()->SpawnActor(spawn, this->GetActorLocation(), this->GetActorRotation());
point->SetVisibility(false);
point->Initialize(Mesh1P->GetAnimInstance());
Inventory.Add(point);
point->AttachRootComponentTo(Mesh1P, FName(TEXT(“WeaponPoint”)), EAttachLocation::SnapToTarget);
if (CurrentWeapon == NULL)
{
CurrentWeapon = point;
CurrentWeapon->WearWeapon(true);
}
}

void AHermesCharacter::NextWeapon()
{	
	Inventory[0]->WearWeapon(true);
}

Inventory[0] is breaking my game what am i doing wrong :X? Pointers gonna kill me ;d

If Inventory[0] breaks your game, it’s probably a nullptr. You’re calling the function NextWeapon while the inventory is empty. This is most likely a problem caused somewhere else in your code.

First, when accessing an array you should always check whether the index is actually valid. Your NextWeapon() function will fail if the array is empty (i.e. no weapon was picked up, but the player is trying to switch weapons). You can use the Inventory.IsValidIndex(…) function, or you can check whether Inventory.Num() is greater than the index you’re trying to access.

Second, since your array is holding actors, you need to make sure that the Inventory field is a UProperty. Otherwise the values added to this array will be garbage collected (meaning: destroyed), because the Engine has no way of detecting that you are still planning to use them. You can make the Inventory array a UProperty by marking it up with the UPROPERTY() macro in your class declaration for AHermesCharacter.

You should also include the actual error message in your questions. That will make it easier for us to determine what exactly is going wrong, thanks!

I know i should but that was just a test code i stared writing line by line and checking if everything work, There is no null pointer exepction index is valid and when it comes too that variable it just crashes My variable declarations are:

UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Gameplay)
	TArray<class AWeapon*> Inventory;



UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Gameplay)
class AWeapon* CurrentWeapon;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay)
UAnimInstance* AnimInstance;

wear weapon:

void AWeapon::WearWeapon(bool wear)
{
	if (PickUpAnimation != NULL)
	{
		// Get the animation object for the arms mesh
		if (AnimInstance != NULL)
		{
			AnimInstance->Montage_Play(PickUpAnimation, 1.f);
		}
	}
	this->SetVisibility(wear);
}

animinstance initialization:

void AWeapon::Initialize(UAnimInstance* AnimInstance)
{
	this->AnimInstance = AnimInstance;
}

Error code : First-chance exception at 0x000007FB8918B1D0 (UE4Editor-Hermes-3607.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x0000000000000358.

If there is a handler for this exception, the program may be safely continued.

It’s not empty i checked by num sie and is valid.

Solved, The reason Of Crash was that array in bp had 2 empty elements god bless me.