Why does my Spawned blueprint actor immidiatly become null?

In my character’s beginplay I spawn a BaseSpell actor, which is a blueprint actor that is a subclass of a C++ class called Spell.

void ADMagicCharacter::BeginPlay()
{
	Super::BeginPlay();

	//SetupSpellList Move to GameMode
	UWorld* const World = GetWorld();
	if (World)
	{
		FActorSpawnParameters SpawnParams;
		SpawnParams.Owner = this;
		SpawnParams.Instigator = Instigator;
		TSubclassOf<class ASpell> SpellClass;
		FVector tVect = FVector(0,0,0);
		FRotator tRot = FRotator(0,0,0);
		SpellClass = Spells;
		ASpell* CurrentPrimarySpell = World->SpawnActor<ASpell>(SpellClass , tVect, tRot, SpawnParams);
		if (CurrentPrimarySpell != NULL)
		{
			GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, CurrentPrimarySpell->GetName());
		}
	}
           
	
}

Spells is a variable that can be set in the editor.
I set Spells for the character to BaseSpell, a blueprint subclassing Spell.

When play testing, the DebugMessage immediately after spawning CurrentPrimarySpell correctly displays the name of CurrentPrimarySpell (BaseSpell_C_#).

Later in the C++ code, I have an OnFire Function that calls another function within CurrentPrimarySpell
And another DebugMessage that displays a red message “NULL” if CurrentPrimarySpell is NULL.

void ADMagicCharacter::OnFire()
{

	if (CurrentPrimarySpell == NULL)
	{
		GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "NULL");
	} else
	{
		CurrentPrimarySpell->OnFire();
	}
}

For some reason, OnFire always shows CurrentPrimarySpell as NULL and displays the red DebugMessage.
There is no other references to CurrentPrimarySpell, and looking in the World Outliner during playtest, shows the BaseSpell actor is still there.
Why is CurrentPrimarySpell becoming NULL, and how can I prevent it?

You are declaring CurrentPrimarySpell in your BeginPlay function as a local variable. If you want CurrentPrimarySpell to exist outside of that function you need to store it in your class header. As you have it now, CurrentPrimarySpell is created just as it was supposed to be, and the immediate check works properly. After BeginPlay finishes that variable is lost (local variables won’t exist outside of the function they are created in), so OnFire won’t know what the value of the variable is.

Just a side note about pointers (like CurrentPrimarySpell), you don’t actually have to compare them to NULL to check them. Using

if(pointerName)

will work like true if the pointer is not null, and false if it is. If you do want to compare them to a value you should use nullptr instead of NULL.

“You are declaring CurrentPrimarySpell in your BeginPlay function as a local variable…”

…uh… crap. Ok, that was a stupid oversight on my part. :o
Thank you for the second set of eyes.