I started C++ in Unreal Engine yesterday and made a function to replace the blueprint version of it.
This is the blueprint function I am trying to replace with C++ code.
Below is the entire code(cpp, header) I made
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "UpdatePositionPawn.generated.h"
UCLASS()
class CTEST_API AUpdatePositionPawn : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
AUpdatePositionPawn();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
//Function #1: UpdatePosition. If other functions need to be added, add it right below this function.
UFUNCTION(BlueprintCallable)
void UpdatePosition();
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
protected:
UPROPERTY(BlueprintReadOnly, Category = "Position")
float Drag=0.25;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Position")
float CurrentSpeed=7500;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Position")
float ThrustSpeed=7500;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "UpdatePositionPawn.h"
#include "Kismet/KismetMathLibrary.h"
#include "Math/UnrealMathUtility.h"
#include "GameFramework/Actor.h"
#include "Kismet/GameplayStatics.h"
// Sets default values
AUpdatePositionPawn::AUpdatePositionPawn()
{
// Set this pawn 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 AUpdatePositionPawn::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AUpdatePositionPawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AUpdatePositionPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
void AUpdatePositionPawn::UpdatePosition()
{
AddActorWorldOffset(UKismetMathLibrary::SelectFloat(ThrustSpeed, UKismetMathLibrary::FInterpTo(CurrentSpeed, ThrustSpeed,GetWorld()->DeltaTimeSeconds, Drag), (ThrustSpeed <= CurrentSpeed)) * GetWorld()->DeltaTimeSeconds * GetActorForwardVector(), true);
}
The UpdatePosition function right above is equal to all the blueprints in the image.
Values of ‘CurrentSpeed’ and ‘ThrustSpeed’ should be edited in runtime by any other blueprints
Like this.
But even I wrote EditAnywhere, BlueprintReadWrite in UPROPERTY, the value of each variables aren’t changing from the first 7500(I tried public instead of protected for the variables and it didn’t work).
Why can’t I change the values by blueprint in runtime?