How to change a text dynamically in a widget?

Hello, I am trying to make a feature in my game where a text in the top right corner will change, telling the player what room they are in as they move between rooms. I am using trigger boxes to accomplish this. My problem is that I do not know how to change the text of a text component and I have done a lot of research but nothing has helped me. Eventually, I ended with this mess:

And here is a screenshot of my widget blueprint:

I’m sure I am close but it doesn’t work. When I launch the game, the game operates fine but I don’t see the text updating as I move around in the box trigger. When I stop the game I get the following two runtime errors:

How do I fix this and how can I dynamically change widget text with a box trigger?

“Access None” means you trying to do something on non existent object, the object varable/link is simply “None”, the reason why they are none is your strange attempt on casting “MainPlayer” and “MainPlayer_Widget”

Cast nodes are not passive/pure nodes, once you call them (and this is the same for any active node with exec pins) and line of exec ends the outputs of node are cleared, in other words they are like local variables which get deleted once function is done. So you need to cast on event not from things in above, because once they done the whole casting gets cleared and when your even is trigger they all empty (None) and you getting “Access None” errors. If oyu want to avoid repetitive casting, cast it once and set casted object to varable and just access that varable.

That said i notice a design flaw in what you trying to do. You seem to try to display name of the room player is in on UI. Insted of making huge level blueprint and for each room make piece of code in it, there a lot sliker way to do it without need to add code for each room:

1.Make your own trigger box blueprint (make a blueprint from TriggerBox class or make a Actor with box component, but first one will transfer over apprance and behavior of trigger box).

2.Inside make a Text varable called “Room Name” and make it public (click the eye)

3.now place it on level for each room and for each box oyu place set “Room Name” varable inside propety tab

4.Now inside player pawn/character blueprint make overlap begin event and check if actor (the “Other” output) that start to overlap is Room trigger box (you trigger box class)

5.If it is cast it to your room trigger box class and read room name varable (you can do that by draging object link and drop it in empty space and search for “Get Varable Name” in this case “Get Room Name”)

6.Set the widget text to what Room Name contains

7.Profit!!!

This way no need to waste time linking things in level blueprint, you just place room trigger boxes you made and code inside your player will just set room name based on which trigger box player start to overlap. You can extend it to even more room properties, like for example you want to invert controls in specific room, you make bool varable inside the room trigger box, you make it public and when player overlap you check if bool is true, if it is you overlap the controls. In that case recomand you to set room trigger box you start to overlap in to varable “Current Room” so you can access properties when they are needed, this will reduce checking procedures on on overlap event.

If you do something in level blueprint that is common to all levels it means you doing something wrong. Level blueprint should contain only code that controls flow of the level a scripting of the level thigns that are only on that level, if you do something common to all levels in it you end up rewriting level blueprint for each level you make over and over again. It’s one of common newbie mistakes.

And tip for the future, engine is part of the game, technically you extending engine it self, so any systems you gonna make try to make them feel like engine features like you extending UE4 with that room system you making

Shadow gave you a very good Answer but it looks like you have general trouble to Understand the flow of BP´s. You can´t just pull something out of nodes you never Execute :stuck_out_tongue_winking_eye: Example: https://i.imgur.com/GoBJ4PJ.png

I highly recommand you to watch this Video too and think step by step what your Code does. Blueprint Communications | Live Training | Unreal Engine - YouTube

I did what you said to do but it still is not working. I was able to get rid of the errors but the text still does not update. Am I casting to the widget properly?