Possible bug (Version 12.5)


I have just been following a tutorial online and came across a possible bug. I was trying to vary the z-position of an actor using a sine wave in C++ but noticed that the ‘startPosition’ variable never changed. I tried placing the actor in multiple spots but as soon as I hit play, the actor would jump back to 0,0,0. The sin function movement worked fine but the field never updates in the details panel of the editor.

I tried deleting the inherited blueprint and creating a new one (once again inheriting the C++ class) and this time the start location seemed to update because when I pressed play, the actor remained in its current position (away from 0,0,0) and began oscillating as expected. I then noticed that the startPosition fields in the details panel did not change still (they always remain at x0.0, y0.0, z0.0) but the code seems to work.

Is this a bug or am I doing something wrong? See code below.



// CPP FILE------------------------------------------------------------------------------------------------------------------------------------

#include "TestCPP.h"
#include "MyTestActor.h"

// Sets default values
 	// 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 AMyTestActor::BeginPlay()

	// Set the 'startPosition' variable to the inital actor position
	startPosition = GetTransform().GetLocation();


// Called every frame
void AMyTestActor::Tick( float DeltaTime )
	Super::Tick( DeltaTime );

	// Add scaled time to current time
	currentTime += DeltaTime * frequency;
	// Actor position varies in the Z-direction over time via sin wave, scaled by magnitude
	SetActorLocation(startPosition + FVector(0.0f, 0.0f, FMath::Sin(currentTime) * magnitude), true);


// HEADER FILE----------------------------------------------------------------------------------------------------------------------

#pragma once

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

class TESTCPP_API AMyTestActor : public AActor
	// Sets default values for this actor's properties

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

	// Define "Movement" properties
	UPROPERTY(VisibleAnywhere, Category = "Movement")
	FVector startPosition;

	UPROPERTY(VisibleAnywhere, Category = "Movement")
	float currentTime = 0.0f;

	UPROPERTY(EditAnywhere, Category = "Movement")
	float frequency = 0.0f;

	UPROPERTY(EditAnywhere, Category = "Movement")
	float magnitude = 0.0f;