First question:
Why single cast and multicast delegate functions don’t need to be UFUNCTION?
I just discovered that only Dynamic delegates and events need to be UFUNCTION, while single and multi cast don’t, but documentation says delegates need to be UFUNCTION.
Second question:
DECLARE_DELEGATE*** kind of macros macros is reported by intellisense as “function definition not found”
is there workaround for this? (excluding disabling intellisense and replacing with VAX because Intellisense become so much faster in recent releases.)
for example, compilable code:
DelegateActor.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Delegates/Delegate.h"
#include "DelegateActor.generated.h"
UCLASS()
class ARCHITECTURE_API ADelegateActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ADelegateActor();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
DECLARE_DELEGATE_OneParam(SingleCastDelegate, FString);
DECLARE_MULTICAST_DELEGATE(MulticastDelegate);
DECLARE_DYNAMIC_DELEGATE(FDynamicDelegate);
DECLARE_EVENT(ADelegateActor, Event);
SingleCastDelegate TestDelegate1;
MulticastDelegate TestDelegate2;
FDynamicDelegate TestDelegate3;
Event TestEvent;
void TestFunc1(FString string);
void TestFunc2();
UFUNCTION()
void TestFunc3();
UFUNCTION()
void TestFunc4();
};
DelegateActor.cpp
#include "DelegateActor.h"
#include "Engine\Engine.h"
// Sets default values
ADelegateActor::ADelegateActor()
{
// 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;
TestDelegate1.BindUObject(this, &ADelegateActor::TestFunc1);
TestDelegate2.AddUObject(this, &ADelegateActor::TestFunc2);
TestDelegate3.BindDynamic(this, &ADelegateActor::TestFunc3);
TestEvent.AddUObject(this, &ADelegateActor::TestFunc4);
}
// Called when the game starts or when spawned
void ADelegateActor::BeginPlay()
{
Super::BeginPlay();
TestDelegate1.Execute(TEXT("Single cast delegate!"));
TestDelegate2.Broadcast();
TestDelegate3.Execute();
TestEvent.Broadcast();
}
// Called every frame
void ADelegateActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void ADelegateActor::TestFunc1(FString string)
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, string);
}
}
void ADelegateActor::TestFunc2()
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("Multicast Delegate"));
}
}
void ADelegateActor::TestFunc3()
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("Dynamic Delegate"));
}
}
void ADelegateActor::TestFunc4()
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Event"));
}
}