Get Variable Name from FString

I’m not sure this will work but nothing ventured and all that.

I have AI characters who have needs with a widget that shows progress bars for each need. I’ve set up C++ functions to return the percentages of each need to the widget can be updated accordingly.

What I’m wondering is if there is any way, using a passed in FString to get the relevant variable in my C++ code so that I can just pass in a Literal Name and have one function rather than have a function for each need.

I know I can do it with a bunch of if statements (ie if (NeedToCheck == “FoodNeed”)) but I’m trying to avoid a bunch of if statements or separate functions if such a thing is possible.

I don’t understand question, what do oyu mean “passed in FString to get the relevant variable”, you mean passing FString to get property which you can read?

Sounds like you could use a multicast delegate to send a FString value name and a Float/int value to a custom event.

    DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FDelegateName, FString, ValueName, float, Value);
    class ClassName :UWhatever
        UFUNCTION(BlueprintCallable, Category = "CategoryName")
	         void FunctionName();
    UPROPERTY(BlueprintAssignable, Category = "CategoryName")
    		FDelegateName MyDelegate;
    void ClassName::FunctionName()

Then you can bind to that delegate event in your event graphs

My AI has needs (hunger, thirst, fun etc.) and instead of having a function for every need, I want the AI Widget to pass in an FString matching the variable name which the C++ will then return the relevant need for.