Download

Programming Quick Start tutorial incompatible with current version of UE4?

Hey everyone! I just went through the “Programming quick start” tutorial to get to grips with how code is implemented into the engine, but I appear to have run into an issue which I am not sure how to resolve.

The problem is that the code does not appear to execute, although it compiles with no errors and there are no errors when launching the level. I even went back and copy-pasted the code from the tutorial [here: https://docs.unrealengine.com/latest/INT/Programming/QuickStart/4/index.html], which is as follows for the header:


// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.

#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;
};

And in the main file:


// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.

#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);
}

I then created an instance of the class and associated the cone-shape with it, as instructed in the tutorial. The cone itself shows but it does not move. I just need to figure out if this is an issue with the current version of the engine or version changes that may have invalidated pieces of the code. Any ideas?

I can’t see anything wrong with this class; but I’m no expert.
Are you sure the actor mobility isn’t set as static? That would prevent it from moving…

The object is set to movable. I’ve performed every single step as linked in the tutorial, which is why I’m wondering if this is an issue with the current version of the engine.

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.

Hey, sorry to necro this thread. I didn’t quite see a rule for it in these forums, and my problem matches the OP’s exactly. I tried to add a debug output to BeginPlay() (I literally even copy/pasted the debug line in your code to my FloatingActor.cpp) and I got something weird.

I compiled using the “Compile” button in the UE4 editor, cleared the log, and clicked “Play” only to find that the debug message never triggers at all. Why would this be the case, out of curiosity?

Edit: Moderators taking a while to approve my second message, so I’ll just say here that my problem was solved by moving “float RunningTime;” above “virtual void Tick(float DeltaTime) override;” where the tutorial says to move it below that line.

I have recently seen several admonishments to never use Tick even when you think you should use Tick. Here we have a quick start using Tick. What is a viable approach to accomplish random floating actors without using Tick? Better to use a timer?

I got some nice effects following this blog post. Make Floating Rocks with the Power of Math™! (Part 1) - Broad Strokes

I am trying to get a sense when I am heading off in bad programming directions.

There is nothing inherently wrong with override Tick(). Yes, you can hurt yourself and you need to be more vigilant there, and you should really try to look for alternate solutions if possible. But like all programming it’s about trade offs. Now for the floating effects you’re talking about, I’d do a new type of movement component so it plays in to the current code path, BUT honestly doing it in tick would also be mostly fine (make sure the tick is pre-physics).

Now, one of the things I see in a lot of contracts I’ve worked is the projects heavy in blueprints often drop to tick to do things and that’s where some performance problems come up. But you just have to be careful.

Thanks for the information, I appreciate the response. Right now not trying to do anything too fancy as I am getting up to speed on what is called when all those objects are spun up.

I had the same issue. I just restart UE and it’s working well now when I compile by UE. I supposed I had brocken the hot reload with Visual Studio.