Passing control from widget back to the game instance?

I’m setting up a UI for my project. This is my first real dive into UIs so I’m on a steep learning curve here.

What happens so far is that during begin play of the player controller a BPI message is sent to a function in the game instance. That function creates a widget and adds it to the screen. The widget has three buttons, ‘New Game’, ‘Load Game’, and ‘Quit’.

I have the ‘New Game’ button tied to an “On Release (Button_NewGame)” event. That looks like this:

The Widget uses the proper BPI (orange box)

The problem is that the game instance object reference is not compatible with the game instance object reference (red box)

How do I make this work? Or is there a better way to do this? I need to get control back to the game instance because it needs to do all the things necessary for a setting up a new game.

This is my first real effort to work with UIs so I’m kind of in the dark here.


Use Get Game Instance followed by Cast To (Your Game Instance Class).

Also, you really should not be calling Collect Garbage. Just let it do its work on its own.

Also, it’s recommended to use On Clicked event for buttons, rather than On Released.

1 Like

Thanks for the response.

Right, I knew that … get game instance is generic … just so many things to learn, it’s hard to remember them all.

I experimented with the On Click instead of On Release. That one actually did what I though On Release did. Thanks for that tip.

A few more questions, if you don’t mind.

I was trying to avoid casting, because everyone says not to when it can be avoided. I thought that was the point of the BPI, so I could avoid that. Is there a better way to do this?

Why shouldn’t I use the Collect Garbage function? I don’t need that widget anymore. Is there some reason why I need it residing in memory for the rest of the game?


Interfaces and casts have different uses. For example, you could have an interaction interface that is implemented by many different actors without a common base class. Then, you could start from a pointer to an arbitrary actor and call the interaction interface so it can handle the interaction, if hooked up for that specific actor.

But in this case, you know that it must be a game instance of your custom class, so you just use the cast to tell it that and get access to the methods of that class.

GC runs automatically every 30 seconds. There isn’t any need to ever do it manually.

1 Like

I’m not sure that I really understood the first paragraph there, but the more I hear these things over and over, the more they will begin to sink in.

Thanks for the info on GC. Good to know.