Where to save variables and functions to communicate from a UMG Widget?


My purpose is to kind of create a widget blueprint content that communicates with a character. This widget blueprint should be able to be reused in another UE4 project if nessecary by migrating it’s asset, if this works.

For example I might have a button in a level menu widget that determines wheter text should be displayed in a chosen level when it’s opened and sets it to a bool (isButtonPressed).
My test setup has been to create a SaveGame function (in first person character) which communicates with the (isButtonPressed) and saves its bool to a SaveGame. Then that bool var has been retrieved with a GetSaveGame function in the newly opened level to do whatever like.

It all seem to work but I am woundering if I am creating the bool variable and function in the “right” class, in terms of making a UMG menu widget reusable in another UE4 project?

I.e. if I have a new character setup in a new UE4 project/ version and I want my UMG menu widget, created in an earlier project, to be able to communicate with this new character setup, should I then have the bool variable and “SaveGame” function created in player controller class instead of the character in the first place?

So basically if am getting it right here, to make my UMG widget to work with another UE4 project character, would I have to migrate the UMG UserWidget, SaveGame and PlayerController class?
If I am totaly off the track here am happy to hear other workflow.

Thank you!

It really depends on the stage you are in, if its prototype stage you might need to iterate a lot also in a new project and then go over it a couple of times.
So what you are saying if the systems in place and works with the Widget, SaveGame and PlayerController class then yes that is fine.

Personally, I always feel especially early that there is no right and wrong if it works, but if it goes into pre-production and production of a game, things change, especially if you are a bigger team.

You should maybe look into this:

How Epic set it up is that I personally would exactly use only that flow in an event or function and depending on the game implement accordingly.
In your instance the Create Save Game Object is triggered by an Event that can come from the Widgets Button and that Event is in your PlayerController**. **

I find the best way to make callbacks from widgets is through event dispatchers. So for each button you would have an event dispatcher like OnSaveButtonPressed etc. and any other Blueprint that might be interested in this event would bind to this event.

Thank you guys for your input! I appreciate it.
Yes I guess it really depends on the stage one is in. And thanks for the links, interesting to watch your videos Martin!

So GarnerP57, when you talk about e.i. an event dispatcher, would you create and call that dispatcher from the button’s event as you named OnSaveButtonPressed in a Widget BP, and then bind it to a set bool variable in a SaveGame function, that is created in the PlayerController?

Yes something like that. Whenever the widget is created in another BP it also binds to the event dispatchers it wants. This way the widget does not need to know who is listening to the button presses. When the widget is created it can also bind widget events to event dispatchers from other places like OnHealthChanged that needs to update the healthbar widget etc.

Ok thanks, that make sense. Just to verify, when the widget is created in another BP, it is to get a reference for the event dispatcher binding, right?

It is the quickest way to get the reference yes, but you may also want to save the reference somewhere to be able to hide the widget without the need for finding the widget again.

Okay sounds good. Thanks!