Show C++ Variable Value in UI Widget

Hi NilsonLima,

I actually found the solution. I started fiddling around with the Observer pattern but the solution is much easier:
I have a variable “ConeCounter” which I update on each event when my character overlaps a cone. In that overlap method I just call your code:



if (locTextControl != nullptr) {
            locTextControl->SetText(FText::FromString(FString::FromInt(this->GetConeCount())));
        }


on the last part I just call “GetConeCount()” which returns the value of my variable “ConeCounter”.

Thanks again - it works perfectly :slight_smile:

Kind regards, Peter

1 Like

@peterw1505 The advantages of Observer pattern is that you can be notified of a value you want to watch without needing to care on “how” you will obtain that value, meaning, it can come from UMG, a blueprint, you just need to define the simplest interface you need. This way you won’t need to worry on testing pointers whenever you want to know a value (because the observed item may no longer exists!) and know syntax for UMG or a particular structure inside a blueprint. Keep on studying the Observer pattern that I am sure you will end up understanding what I mean here.

My pleasure help.