Unreal C++/Blueprint

Classé dans : Non classé | 0
UENUM(BlueprintType)
 enum class EPressure : uint8
 {
     Middle,
     Inflate,
     Deflate
 };

// in some class
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Switch Variables") 
float DesiredIntensity;

UFUNCTION(BlueprintCallable)
int GetSomething(float index) const; // const to make it pure
// DELEGATE stuff
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class PLUGIN_API UMyClass: public UActorComponent
{
GENERATED_BODY()
 // use dynamic multicast, more option here
 DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnCustomDispatch);

public:
UPROPERTY(BlueprintAssignable)
FOnCustomDispatch OnCustomDispatch ;

}
[...] // In some function
OnCustomDispatch.Broadcast();

// In some other class MyOtherClass
// Declare a func
UFUNCTION()
void OnBroadcastHappen();

UMyClass* FoundUMyClass;
FoundUMyClass = Cast<UMyClass>(UGameplayStatics::GetActorOfClass(GetWorld(), UMyClass::StaticClass()));
FoundUMyClass->OnCustomDispatch.AddDynamic(this, &MyOtherClass::OnBroadcastHappen);
more info : https://docs.unrealengine.com/en-US/Gameplay/ClassCreation/CodeAndBlueprints/index.html
Delegate : https://unreal.gg-labs.com/wiki-archives/macros-and-data-types/delegates-in-ue4-raw-c++-and-bp-exposed