Download

Accessing private field in tick

Hi,

This might be because of my misunderstanding. I’m not very experienced with C++.

I’ve declared a private field in header file like this:



private:
       int ForwardsMovement;


Then in my actual CPP file I’m setting a value for that field like this:



void ACameraDirector::CameraForwardStart()
{
       GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, TEXT("FORWARD START"));
       ForwardsMovement = 10;
}


Then in the tick I’m checking for the value of the ForwardsMovement field in an if statement:



void ACameraDirector::Tick(float DeltaTime)
{
          Super::Tick(DeltaTime);
          if (ForwardsMovement > 0)
          {
                  GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, TEXT("FORWARDS"));
          }
}


For some reason the ForwardsMovement always seems to be 0 however. Not sure what I am missing here. When I am logging the value of the field after setting it I can see it’s been set to 10. Also I’ve got method called CameraForwardStop where I am setting the value to 0 and when logging the value before setting it to 0 it is 10. Can’t get my head around why the value does not seem to be the same in the tick. HALP!

Are you sure you’re even ticking? Have you enabled the tick on the actor?

Check your Tick and CameraForwardStart functions for calling.

I am ticking as I can log the field outside of the if statement and it’s always 0

Where are you calling CameraForwardStart()?