Trying to cast to a widget called “Subtitles” which is in the scene and have it change the text within that widget. I believe I know what I’m doing when it comes to using variables to change set the text. However, my casting is failing and I’m not sure how to fix it.
This is the error I get. Subs Var is in “Subtitles” and I am trying to set it within this other blueprint.
What is the correct way to cast to it? I only have one in the scene so don’t really need a “for each loop”. I’ve casted to widgets in the past but never seem to have this issue.
The best way is when you create the widget store it in a persistant variable somewhere, either game instance or even your player. depending where you need it
then to access it you just reference the variable object
I have this set up just now but keep getting an error.
All these examples return no errors when doing the exact same thing. Is this different because its a VRPawn?
Ok well you are trying to cast a widget to Vrpawn that wont work. Is the widget stored inside of the intercom blueprint or the player? If in the intercom you just access the widget in your stored object reference variable. If in your player, you will need to GetPlayerPawn then cast it to your blueprint type (is that what VRPAWN is?) Then drag off that and Get insertwidgetvariablehere
I’m not entirely sure how to do this correctly but I’ve attempted it and still not working. When I drag out of “HUDWidget”, none of its variables show up.
You are nearly there if you need subvars get rid of that last set you dont need it, drag off your hudwidget and u should have GetSubsvar or SetSubsVar as long as hudwidget is of type subtitles (thats what you called your widget right?)
I can see hudwidget in your components, now is that the same widget as subtitles? Or is subtitles on that widget?
Alternatively, I’ve found that this works although it’s not as neat but will mark as solution for now in case any other’s look. Although this does work, I could like to workout why your suggestion doesn’t work as that seems like it should unless there is some sort of visibility/“not editable” box that needs ticked
It is also worth noting that adding a “Delay” is necessary for the script to work. I think this is because it runs before the widget exists? So adding a short 0.2 delay fixes this and it works.
That may have been the problem that youvwas calling subtitles before it finished being added to the viewport. A way round this is to do a isvalid? Check if true access widget. If false run a delay 1 tick and send it back to try again