Accessed None trying to read property [Pawn]

I am trying to set the initial position of a camera on load. Then I should be able to move it upwards when I press the Up arrow in the keyboard. Here is my blueprint. SpawnCamera and MoveCameraUp functions are scripts I made in C++

image

I get the error in the log saying Accessed None trying to read property DomeCameraPawnReference for both BeginPlay and Keypress Up events.

I’ve read that such error means there’s something wrong with the Target, but I’m not sure what is wrong in mine.

If it helps, here’s also my C++ codes:

void ADomeCameraPawn::SpawnCamera()
{
FActorSpawnParameters spawnParams;
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
GetWorld()->SpawnActor(CameraActorToSpawn, InitialTransformPosition, spawnParams);
}

void ADomeCameraPawn::MoveCameraUp()
{
FVector Location = GetActorLocation();
FVector VectorUp = FVector(0, 0, MovementIncrement);
Location += VectorUp;
SetActorLocation(Location);
}

TIA.

Additional info: I saw this post: Accessed None trying to read property Stored Pawn but it didnt help me.

" Accessed None trying to read property DomeCameraPawnReference"
Means that DomeCameraPawnReference isn’t instantiated. It’s empty. It doesn’t reference anything. It doesn’t exist.

If SpawnCamera spawns DomeCameraPawnReference, and SpawnCamera is in the class that DomeCameraPawnReference is, you should make SpawnCamera static and return a reference to the spawned actor.

1 Like

Figured it out. The answer is casting: