Is tick resetting my float?

Hi All,
Fairly new to Unreal so this might be something obvious.
So the set up is: I have a player controller setting a float variable in a pawn .cpp

void AEditorPawn::SetCameraYaw(float value)
{
	UE_LOG(LogTemp, Warning, TEXT("setcamerayaw: %f"),value);
	if(value != 0.0f)
	{
		CameraRotationYaw = value;
	}	
}

The Log in this code snippet gives out the correct value.
However, The Log in my Tick function accessing the same float variable keeps returning 0.0000.

void AEditorPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	UE_LOG(LogTemp, Warning, TEXT("setcamerayaw: %f"),CameraRotationYaw);
}

Is this expected behaviour?
FYI: The value set in SetCameraYaw() is set via a bindAxis. Don’t know if this is relevant because if I hardcode the float variable to 2.f or something within the SetCameraYaw(), it remains 0 in the tick.

Thanks for your reply!

Hi @Jeffrey1989 !

It looks like your variable CameraRotationYaw is being garbage collected, can you show how are you declaring it on the EditorPawn.h file?

@barracius-AOne
Thank you so much for replying and taking an interest in my issue.

My variable is declared in the .h as followed:

private:
float CameraRotationYaw;

I think it’s definitely being garbage collected, to prevent that you have to add UPROPERTY() just above your variable. Like so:

private:

UPROPERTY()
float CameraRotationYaw;
      

There are also very handy things called specifiers in Unreal that you can put inside the parenthesis that will help you in the future more info here on specifiers

Garbage collection applies only to objects with a dynamic storage duration. float is a built-in type and allocates nothing at all, so how it can be GC’d?
Problem lies somewhere else.

@barracius-AOne
Thank you so much for your reply.
I have tested it out. and unfortunately, this does not work.

How you instantiate AEditorPawn? Where your store it?

@Emaer The AeditorPawn is the default spawned pawn from the gamemode.

I had no idea, thought it applied to all variables :sweat_smile:

What I’m thinking then is that it is getting reinitialized or reset somewhere else.

On the variable, write as a specifier VisibleAnywhere with that you can click on your actor when it’s already playing and you can check that variable in real time. Another thing you could try is using the specifier EditAnywhere and then you can change the value manually to see if it’s changing by itself on runtime.

UPROPERTY(EditAnywhere) // UPROPERTY(VisibleAnywhere)
float MyFloat

When I come across this kind of problem, it’s usually because the Actor I’m editing isn’t the same as the Actor I’m looking at.

Try editing your functions to print out the memory address and name of each actor

void AEditorPawn::SetCameraYaw(float value)
{
	UE_LOG(LogTemp, Warning, TEXT("(%s@%p) setcamerayaw: %f"),*GetName(),this,value);
	if(value != 0.0f)
	{
		CameraRotationYaw = value;
	}	
}
void AEditorPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	UE_LOG(LogTemp, Warning, TEXT("(%s@%p) setcamerayaw: %f"),*GetName(),this,CameraRotationYaw);
}

My apologies guys for the late reply. I was on a holiday.
@Vacui. It logs correct in the SetCameraYaw Function, but not in the Same tick function,
So I assume that would be the same object then?
@barracius-AOne
Changing the properties did not help as well.

I appreciate the help everyone is offering, guys!