Member variable not staying assigned

Hi

I’m sure I’m doing something wrong as this is really peculiar.

I have a custom c++ actor component which has a private member variable currentVolume, which is meant to be assigned a pointer to an object of an actor class.

I assign the currentVolume via a blueprint callable function OnOverlapBegin(), which is called when an actor containing my actor component begins. That all works fine, but when I later try and use the accessor (GetCurrentVolume()) for currentVolume, I find that it is a null pointer. I’ve not deleted the actor it was pointing to, or anything like that.

In the code below I’ve used a lot of UE_LOGs to try and narrow down where the problem is. When I actually start the game I get the following in my output log:

MVPNewLog:Warning: UTestComponent::OnOverlapBegin
MVPNewLog:Warning: UTestComponent::OnOverlapBegin Other Actor: VASFVVolume_2
MVPNewLog:Warning: UTestComponent::OnOverlapBegin Cast Successful
MVPNewLog:Warning: UTestComponent::OnOverlapBegin currentVolume set to VASFVVolume_2

...

MVPNewLog:Warning: UTestComponent::GetCurrentVolume CurrentVolume is null?

So it looks to me as though the pointer gets assigned fine in OnOverlapBegin(), but once I try and access it with GetCurrentVolume() it has reset to null??

TestComponent.h

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class MVPNEW_API UTestComponent : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UTestComponent();

	// Called when the game starts
	virtual void BeginPlay() override;

	//Return the current volume pointer of the actor component
	UFUNCTION(BlueprintCallable, Category = "VASFV Navigation")
		AVASFVVolume* GetCurrentVolume() const;

	//Called by Actor blueprint/c++ when we overlap something new. Check to see if it is a VASFV Volume, and track it if it is.
	UFUNCTION(BlueprintCallable, Category = "VASFV Navigation")
		void OnOverlapBegin(class AActor* OtherActor);
		
	UPROPERTY(VisibleAnywhere)
		FString currentVolumeString;

private:
    UPROPERTY()
	AVASFVVolume* currentVolume; //the current volume of the Actor
	
};

TestComponent.cpp

#include "MVPNew.h"
#include "TestComponent.h"

void UTestComponent::OnOverlapBegin(class AActor* OtherActor)
{
	UE_LOG(MVPNewLog, Warning, TEXT("UTestComponent::OnOverlapBegin"));

	UE_LOG(MVPNewLog, Warning, TEXT("UTestComponent::OnOverlapBegin Other Actor: %s"), *OtherActor->GetHumanReadableName());

	//determine if we have hit a volume, which, and which vertex/node in edgeMap it is!

	if (OtherActor->IsA(AVASFVVolume::StaticClass()))
	{
		currentVolume = Cast<AVASFVVolume>(OtherActor);

		if (currentVolume)
		{
			UE_LOG(MVPNewLog, Warning, TEXT("UTestComponent::OnOverlapBegin Cast Successful"));
		}

		currentVolumeString = *currentVolume->GetHumanReadableName();
		UE_LOG(MVPNewLog, Warning, TEXT("UTestComponent::OnOverlapBegin currentVolume set to %s"), *currentVolumeString);
	}

}

AVASFVVolume* UTestComponent::GetCurrentVolume() const
{
	if (currentVolume)
	{
		UE_LOG(MVPNewLog, Warning, TEXT("UTestComponent::GetCurrentVolume %s"), *currentVolume->GetHumanReadableName());
		return currentVolume;
	}
	else
	{
		UE_LOG(MVPNewLog, Warning, TEXT("UTestComponent::GetCurrentVolume CurrentVolume is null?"));
		return nullptr;
	}
}