Get game state inside Editor Widget

I have an Editor Widget and inside of it I created a blueprint for some button click event.

Unfortunately, when I use the “Get game state” node (or any similar), it always returns null.

I understand that it’s correct while I don’t hit Play in Editor (there’s no game state instance).
But once I do hit Play, it’s all the same when I click the button on Editor Widget - it returns null.
At the same time, regular widgets inside game window do return the game state reference.

So, making assumption that the game is playing (I hit Play button), how to get access to Game State inside Editor Widget (like it’s possible in normal Widget)?

Here’s the step-by-step video to reproduce the problem on fresh new Unreal Engine game:


Here’s the screenshot with example blueprint and effect of Play (in Editor) and button click:

Same when I cast to my custom game state that I use in the game:

It works in User Widget and fails in Editor Widget. I can replicate it on fresh new project in UE 4.22

UPDATE:

Yet another try. I added Actor of my custom Blueprint type to the scene.
In it, I added getGameState() method exposed to blueprint from C++.

I created two very simple, identical blueprints: one for User Widget and one for Editor Widget.

They both iterate through Actors of my type, find exactly one of them (as they should) and call to getGameState().

The one from User Widget returns the correct memory address of game state:

291271-s1.jpg

While at the same time, the exact same blueprint from Editor Widget returns null:

291272-s2.jpg

Here’s the screenshot of Unreal Engine Editor (1 - button on User Widget, 2 - button on Editor Widget).

Also note: the world pointer is different for User Widget and Editor Utility Widget.

p.s. I am working on simple, single-player case.

Hmm weird can you drop few screenshots of your blueprints?

Sure thing! I’ve just updated the question with screenshot. I am able to replicate it in any fresh new game project.

Cast fails if you using the default game state its GameStateBase and not GameState, and you don’t need to cast for that.

I don’t think it’s the case. Casting to any game state type (base, standard or my own custom one) is failing as well in Editor Widget, while works in User Widget (exact same blueprint).

Same for e.g. comparing Get game state result node with null (it returns true in Editor Widget blueprint and false in spawned User Widget).

I have updated my question with the second screen.

I checked it already in a button widget and it works for me without casting, so I still think that its a cast problem.

Try this:
1.Not the correct game mode is selected as your project game mode.
2.The game state not set correctly in the project game mode.
3.Removing the cast.

If all of this not working you can just tell me how you creating this widget step by step, or dropping of the packaged project and I come back to you in a jiffy.

Hi, thank you for your time and determination.

The get game state inside Editor Widget returns null so whatever cast I do it fails, using it as is also fails as it’s just null.

The get game state inside User Widget works perfectly, casting too.

I triple-checked the game mode selection but I don’t think it’s the problem (if it would, casting would fail but before casting get game state would not return null to begin with).

I start to think that it’s some Engine’s bug that prevents Editor Utility Widget from access game state (which normal User Widgets can).

I will do some more tests and if they all fail, I will prepare the step by step or package with minimal amount of dependencies that fails this way.

Once again thank you for support!

Ok, here’s step by step to reproduce the problem: Unreal Engine - Editor Widget can't access Game State - YouTube

I decided to record it because describing I could omit something important by mistake.

If you follow it, you will get the same problem I have - get game state returns NULL but only for Editor Widget, while it works for User Widget.

Hey, had you time to look at it?

Yeah I looked at it, I don’t think its a bug I think that the UI Editor Widget is built only for the editor and that why it can’t even connect to the runtime. I tried to find ways around it but failed, I think that only the staff here can help you with that sorry.

Ok I think I might have an answer for you. I went poking around in source and UEditorWidgetUtility is specified as needing a world context (I’m not an expert but I’m guessing that because of the game initialization order there is no way to see the current game state). However in blueprints you can use the GetGameWorld node as way to get the world context in the editor widget. This will only work when the game is running and I’m going to do some poking to find out who the world settings panel gets populated

Hmm interesting can you drop a screenshot cause I can’t really find the function, thanks

I’ve found that that upgrading between 4.22 and 4.23 fixes it (for future reference).

Hi. It does returns some World context I can use to Get Game State function. Nerveless, in another project Get Editor World node returns null for some reason? And yes, the game is running in Editor.

yeah i was noticing that as well and i have no idea why

Still, thank you for spending your time investigating it!