UE4 c++類派生藍圖類

先列代碼

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

#pragma once

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

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

 UPROPERTY(EditAnywhere, BlueprintReadWrite,Category = "Damage")
  int32 TotalDamage;

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Damage")
  float DamageTimeInSeconds;

 UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Transient, Category = "Damage")
  float DamagePerSecond;

 UFUNCTION(BlueprintCallable, Category = "Damage")
  void CalculateValues();

 UFUNCTION(BlueprintImplementableEvent, Category = "DAMAGE")
  void CalledFromCpp();

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

 virtual void PostInitProperties() override;

 virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
 
 
};

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

#include "testunrealc.h"
#include "MyActor.h"


// Sets default values
AMyActor::AMyActor()
{
  // 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;
 TotalDamage = 200;
 DamageTimeInSeconds = 1.0f;
 DamagePerSecond = TotalDamage / DamageTimeInSeconds;

}

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

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

}

void AMyActor::PostInitProperties()
{
 Super::PostInitProperties();
 this->CalculateValues();
}

void AMyActor::CalculateValues()
{
 DamagePerSecond = TotalDamage / DamageTimeInSeconds;
}

#if WITH_EDITOR
void AMyActor::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
 this->CalculateValues();
 Super::PostEditChangeProperty(PropertyChangedEvent);
}
#endif

void AMyActor::CalledFromCpp_Implementation()
{

}

 

從此類中派生出兩個藍圖類,其中一個藍圖類在編輯框的值能夠隨着輸入值的變化而變化,一個不能隨時計算

 

 

原因在於


void AMyActor::PostInitProperties()
{
 Super::PostInitProperties();
 this->CalculateValues();
}

#if WITH_EDITOR void AMyActor::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) {  this->CalculateValues();  Super::PostEditChangeProperty(PropertyChangedEvent); } #endif