gedamial
(gedamial)
November 27, 2015, 6:43pm
1
Hello guys.
I’ve made a similar project using Blueprints, now I’m moving to a C++ project, since I am an experienced programmer in C++. The problem is… that I’m not experienced with Unreal Engine classes lol
I would create an Actor that would rotate around his Z axis every second.
With blueprints, I did so:
How to do this with a C++ Class?
I did this:
But it doesn’t work when the game starts.
Thanks in advance!
2 Likes
Every tick you set actor’s rotation to (0,0,0) and then add (0,0,4) to it, resulting rotation is always (0,0,4). Remove SetActorRotation().
gedamial
(gedamial)
November 27, 2015, 7:53pm
3
void APickup::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
FRotator rotation = FRotator(0.f, 0.f, RotationSpeed);
AddActorLocalRotation(rotation * DeltaTime);
}
This doesn’t work. (RotationSpeed is 4.f)
That’s weird, just to be sure I tried this on a random class and it works. I don’t know any more context so can’t say much. Try this:
Include “Engine.h” and then add this line to your tick function
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("rotation: %s"), *rotation.ToString()));
It should print the rotation variable
gedamial
(gedamial)
November 27, 2015, 8:19pm
5
Nothing gets printed out
// Called every frame
void APickup::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
FRotator rotation = FRotator(0.f, 0.f, RotationSpeed);
AddActorLocalRotation(rotation * DeltaTime);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("rotation: %s"), *rotation.ToString()));
}
It seems that for some reason tick function is not being executed. Post the code of your class please.
But before you do that try this:add this line
PrimaryActorTick.bCanEverTick = true;
to constructor and compile
gedamial
(gedamial)
November 27, 2015, 8:35pm
7
Oh my gosh, I don’t know for which reason I had that disabled. I didn’t even checked that.
Thanks!