Accesing variable in another blueprint in event on construction of a widget?

HI, My widget has an event on construction which has a code of blueprint in which it needs to acces an array variable from game mode blueprint. But the problem is that on getting the game mode from the widget blueprint, on debug, it shows “not in scope”. In my understanding widget blueprint is unable to access or communicate with gamemode blueprint to get the required array variable. I need to know why and if the answer is that construction events cant access gamemode blueprints then how to get a variable from another blueprint from the construction event?

PS: I have tried the same thing with Gamestate and Gamestate base but results were the same. I am unable to access the variable anyhow for now.


It should be accessible, make sure to set the game mode from your world setting(the tab on the right windows usually)

If that widget is run from the client side, it can’t access the server game mode.

1 Like

Game mode is set to the BP_gamemode which is the desired gamemode and its a single player game so client and server should be same.

I have read in the forums that construction events cant access the game mode thus i tried the same thing with gamestate but results are same.

Construction Script during editor time yes it can’t access game mode but EventConstruct should work:

Does your event triggering ?, try to add a print string after the event construct.
It get called when you add that widget to viewport.

1 Like

Yes the event is running , in fact, cast to bp game mode is not failing, its just the ‘get game mode’ has no return value.

this is the blueprint sending it for reference

So… you can access towers and everything works fine?

In Editor: Try selecting that node and press F9 to add a breakpoint to it.

Ingame: when the widget is added to viewport, it should point it on that breakpoint, mouseover the return value of game mode should return the proper values since the casting isnt failing.

I think your game mode is working, it just missing the breakpoint most likely.

No thats the problem both the game mode and the variable “Towers” is not in scope

That was not my question, though. If the cast does not fail, it means the object is accessible. Add a string variable to the game mode, access it instead of Towers and print its value. What do you get?

Your event is not being called, it should have that red arrow overhead:

With string variable and printing it getting the BP_Gamemode but on debug it still shows not in scope plus the value of variable “Tower” is also not in scope which is the main problem.

I also tried something in the meanwhile which is casting to gamemode and calling the variable from outside this function directly in the event construct and adding an input to get static meshes function of the same type as tower variable. In this case everything works fine until code enters the function and then the variable is out of scope or “not in scope” to be exact

Then why is it printing the string?


THis is what you meant?


Yes, then you keep stepping in with F11

yes sent some screenshots above

Your game mode is working properly then.