I wanted to use templates with UCLASS and came to realization that it is not possible to use templates with macros so i came to the conclusion to replicate that bevahiour with macros themself. As i know it is possible to call macros in other macros, but i am not able to see anything in blueprint.
#pragma once
#include "CoreMinimal.h"
/*
*Needs
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FClampLimitHit, float, spillover); once in class body
*/
#define CLAMPED_VALUE(var_name) \
\
public: \
\
UPROPERTY(EditAnywhere, Category = Interactable, BlueprintSetter = Set##var_name##Min, BlueprintGetter = Get##var_name##Min) \
float var_name##Min=0; \
\
UPROPERTY(EditAnywhere, Category = Interactable, BlueprintSetter = Set##var_name##Max, BlueprintGetter = Get##var_name##Max) \
float var_name##Max=2; \
\
UPROPERTY(EditAnywhere, Category = Interactable, BlueprintSetter = Set##var_name##Value, BlueprintGetter = Get##var_name##Value) \
float var_name##Value=1; \
\
public: \
UFUNCTION(BlueprintGetter) \
float Get##var_name##Min() { \
return var_name##Min; \
} \
UFUNCTION(BlueprintGetter) \
float Get##var_name##Max() { \
return var_name##Max; \
} \
UFUNCTION(BlueprintGetter) \
float Get##var_name##Value() { \
return var_name##Value; \
} \
\
\
UFUNCTION(BlueprintSetter) \
void Set##var_name##Min(float value) { \
var_name##Min = value; \
if (var_name##Value < var_name##Min) { \
var_name##Value = var_name##Min; \
} \
} \
UFUNCTION(BlueprintSetter) \
void Set##var_name##Max(float value) { \
var_name##Max = value; \
if (var_name##Value > var_name##Max) { \
var_name##Value = var_name##Max; \
} \
} \
UFUNCTION(BlueprintSetter) \
void Set##var_name##Value(float value) { \
var_name##Value = value; \
if (var_name##Value < var_name##Min) { \
On##var_name##LowerLimitPassed.Broadcast(var_name##Value); \
var_name##Value = var_name##Min; \
} \
else if (var_name##Value > var_name##Max) { \
On##var_name##UpperLimitPassed.Broadcast(var_name##Value); \
var_name##Value = var_name##Max; \
} \
} \
UFUNCTION(BlueprintCallable) \
void Add##var_name##Value(float addition) { \
Set##var_name##Value(var_name##Value + addition); \
} \
UPROPERTY(BlueprintAssignable) \
FClampLimitHit On##var_name##UpperLimitPassed; \
UPROPERTY(BlueprintAssignable) \
FClampLimitHit On##var_name##LowerLimitPassed; \
\