Programming Quick Start tutorial incompatible with current version of UE4?

Hi, DaveBot. I just created a project called QuickStart, added FloatingActor (derived from Actor) to it, and copy-pasted your code. After pressing the “compile” button in the editor, I placed a single FloatingActor in the level and attached a cone mesh component to it. At that point, pressing the play button did cause the cone to float up and down as expected. I’m not sure what might have happened. I did this in the latest released version of the engine, UE 4.10.2. Here are my .h and .cpp files:


// Fill out your copyright notice in the Description page of Project Settings.

#include "QuickStart.h"
#include "FloatingActor.h"


// Sets default values
AFloatingActor::AFloatingActor()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned
void AFloatingActor::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AFloatingActor::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );
	FVector NewLocation = GetActorLocation();
	float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));
	NewLocation.Z += DeltaHeight * 20.0f;       //Scale our height by a factor of 20
	RunningTime += DeltaTime;
	SetActorLocation(NewLocation);
}




// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "GameFramework/Actor.h"
#include "FloatingActor.generated.h"

UCLASS()
class QUICKSTART_API AFloatingActor : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AFloatingActor();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

	float RunningTime;
};


I’m not sure what could have gone wrong here. Did you compile your project in Visual Studio? If so, you might have recompiled for a different build type that what you’re running, meaning your code changes wouldn’t show up. Using the “compile” button in the editor can help this, since it will always compile for the build you’re currently running. I might also suggest placing some debug logs in the BeginPlay() and Tick() events. Like this:



void AFloatingActor::BeginPlay()
{
	Super::BeginPlay();
	UE_LOG(LogTemp, Warning, TEXT("Floating Actor Begin Play called!"));
}




void AFloatingActor::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );
	FVector NewLocation = GetActorLocation();
	float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));
	NewLocation.Z += DeltaHeight * 20.0f;       //Scale our height by a factor of 20
	RunningTime += DeltaTime;
	UE_LOG(LogTemp, Warning, TEXT("Floating Actor ticking: New height = %f"), NewLocation.Z);
	SetActorLocation(NewLocation);
}


Under the “Window” drop-down, in “Programmer Tools”, you will see “Output Log”. Make sure that’s checked and you can see the output log window. Your UE_LOG output will show up there. I’d suggest right-clicking and clearing the log. Our text is classified as “warning” level, so it will show up in yellow and should be easy to read. Press play and see what shows up. If you get just the BeginPlay output, but not a long stream of Tick output, then ticking isn’t working on your actor. If you see a constant, rapid stream of tick output, then your actor is ticking, and I would suggest checking the “height” value in the output.

Hopefully, something in there will resolve your issue. If not, or if you’re not using 4.10.2, please reply and tell us what happened.