And if you stored the correct type, there’d be no need to cast in the first place.
But. Perhaps there is a better way to organise it all rather than rely on the Game Mode. Since we want to read the sphere-bluerprint’s data, why not create the widget in the sphere actor rather than in the Game Mode. You may have your reasons, of course and it can be done.
Try this in the sphere actor:
Now, instead of the widget trying to pull data from a world object, the sphere actor is pushing its own data into its own widget.
Alternatively, if you need to keep the widget and the sphere actor unrelated, and want to use a reference variable:
- in the widget
The above assumes the sphere-actor is a possessed pawn.
This is what @eldany.uy referred to in regards of populating a reference variable. Think of creating a variable as of reserving memory for it, but we also need to tell it which data to actually store inside.