Blueprint Child Values Erasing On Startup

I edited the code so that I can have the actors moving between two specific points in a way I liked better, but all of the values in the child blueprints are being set to 0 whenever I launch the project.
I was wondering if anyone knew what the reason might be? (This is in UE5 by the way)

header file

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MovingPlatform.generated.h"

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

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;


public:

	UPROPERTY(EditAnywhere)
	FVector StartPos;

	UPROPERTY(EditAnywhere)
	FVector EndPos;

	UPROPERTY(EditAnywhere)
	float Speed;

	UPROPERTY(VisibleAnywhere)
	double TotalMoveDistance;

	UPROPERTY(VisibleAnywhere)
	double DistanceMoved;

	UPROPERTY(VisibleAnywhere)
	bool AtEnd;

private:

	void MovePlatform(float DeltaTime);

};

cpp file


#include "MovingPlatform.h"

// Sets default values
AMovingPlatform::AMovingPlatform()
{
	// 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 AMovingPlatform::BeginPlay()
{
	Super::BeginPlay();

	TotalMoveDistance = FVector::Dist(StartPos, EndPos);
}

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

	MovePlatform(DeltaTime);
}


void AMovingPlatform::MovePlatform(float DeltaTime)
{
	// Get the Current Location of the Player
	FVector CurrentPos = GetActorLocation();
	FVector TargetPos;

	// If the Player as not reached the end
	if (AtEnd == false)
	{
		// Move the Player towards the EndPos Location
		TargetPos = ((EndPos - StartPos) * Speed) * DeltaTime;
		DistanceMoved = FVector::Dist(StartPos, CurrentPos);
	}
	// Otherwise
	else
	{
		// Move the Player towards the StartPos Locations
		TargetPos = ((StartPos - EndPos) * Speed) * DeltaTime;
		DistanceMoved = FVector::Dist(EndPos, CurrentPos);
	}

	// Move the Player
	SetActorLocation(CurrentPos + TargetPos);

	// If the Player has moved further than the difference between StartPos and EndPos
	if (DistanceMoved > TotalMoveDistance)
	{
		if (AtEnd == false)
		{
			AtEnd = true;
		}
		else
		{
			AtEnd = false;
		}
	}
}

Have you seen the lecture on the issues with Live Coding? I suggest you disable it.

1 Like

Disabling it fixed the issue.
Thank you so much!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms