How to set up game instance C++

Hi I’m trying to set up a game instance to carry data through my maps. However, I’m having trouble setting it up. I keep getting an access violation nullptr thing now matter what code from the instance I call. My code looks like:

Header:
UPROPERTY(EditAnywhere)
UAssignmentGameInstance* GameInstanceRef;

Cpp:
In the beginplay function,
GameInstanceRef = Cast(UGameplayStatics::GetGameInstance(GetWorld()));

then when I call the code from the game instance class
GameInstance->IsDead = true;

thank you

So Turns out where I was referencing it in a different class, I had commented out the cast. What an idiot