After building I cannot find the CalculateFunction or the Damage category inside the blueprints. The function is public, but my guess is it would not compile when it is anything other then public. What am I missing?
My guess is that this is a hot reload issue. You can find a detailed explanation of the issue here, but the short version is that UPROPERTY()s and UFUNCTION()s are not always properly updated after a hot reload. Thankfully, the work around is simple - close and reopen the editor and everything should be in the right place.
I’ve notice that if i change the Category (from DAMAGE to DAMAGETWO) in visualstudio (and rebuild the project) the HOTRELOAD in blueprint recognize something happen, but pressing the right button, the new category (DAMAGETWO) is still not available (as pointed out by Madmenyo). If i restart the editor, the DAMAGETWO is available
Am I missing something?
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"
UCLASS()
class MYPROJECT_API AMyActor : public AActor
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Damage")
int32 TotalDamage;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Damage")
float DamageTimeInSeconds;
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Transient, Category = "Damage")
float DamagePerSecond;
// Sets default values for this actor's properties
AMyActor();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
virtual void PostInitProperties() override;
void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
UFUNCTION(BlueprintCallable, Category = "Damage")
void CalculateValues();
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyProject.h"
#include "MyActor.h"
// Sets default values
AMyActor::AMyActor()
{
TotalDamage = 200;
DamageTimeInSeconds = 1.f;
}
// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
Super::BeginPlay();
}
void AMyActor::PostInitProperties()
{
Super::PostInitProperties();
CalculateValues();
}
void AMyActor::CalculateValues()
{
DamagePerSecond = TotalDamage / DamageTimeInSeconds;
}
#if WITH_EDITOR
void AMyActor::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
CalculateValues();
Super::PostEditChangeProperty(PropertyChangedEvent);
}
#endif
My rule of thumb is that if you change something in the header file, you can’t use hot reload. Just rebuild the project in visual studio. If you only change code in the CPP files, then the hot reload works great.
If you’re doing a build from VS and still not seeing the function in your blueprint, then there’s something else going on. It looks correct in your posted code though.
Did you make sure to untick that context option in BP? I had the same problem as you, but when I de-selected it I found my function in the set category.
That used to be the case, but these days (in 4.7) you should be able to change headers as well and it should all work! If it doesn’t that is probably a bug, and AnswerHub is the best place to post those.
I don’t trust hot reloads 100% because they still cause problems for me if I change a lot. For instance if I add a new BlueprintCallable function, then hot reload my changes, add the function to a BP then attempt to save that BP, I get an error telling me the BP couldn’t be saved due to an external reference. If I however, add the function then recompile from Visual Studio, no problems.
Well I also happen to be following the same introductory tutorial and I am having the same issue as well with the UFUNCTION macro too… gonna try restarting my editor and see what happens.
Yea so after restarting the editor and turning off context sensitive the function shows up as well as its respective category. So this appears to be a bug of some sort as I had also tried building from Visual Studio and it does not show up either.