How to get the reference to a Ui wiget spawn within an actor

So I am spawning this actor that contain a ‘‘flying’’ Ui widget

Am I am trying to update the book title value.

But It seem I cant get a reference to the variable
‘Book Spine UI’ does not inherit from ‘Book Spine 3DWidget’ ( Cast To BookSpineUI would always fail).

So I (assume) I am getting the reference to the spawned actor correctely but I cannot acces the variable inside the actor widget.

Thanks

as the warning says, you don’t need to cast to a class you already have a reference to.

The Spawn BookSpineUI, already gives you a valid reference to the class you just spawned, Casting to it again is unnecessary.

You use Cast to move from a parent class to a child class. eg: “GetAllActorsOfClass: Actor” Cast “Actor” to “ChildActor”. And it’ll succedd if ChildActor is in fact a child of the Actor Class.

The Text of “Book Title” is in the Widget. Not in the Actor. So you need to get its widget component and do it there.

Get the actor, get its widget component (your was called BookTitleWidget), get the generic widget object, cast to the actual widget class, get its text variable, set the new text.

However, you’re kinda not supposed to to do that much stuff outside the classes,

What you should to is create a function inside the actual widget class called: UpdateText

263663-3.png

Then on the book class you create a Text Variable called “Title”, and set it as Instance Editable and Exposed on Spawn. Then on BeginPlay do this:

so, with the “Exposed on Spawn” Variable, whenever you spawn that class the Title variable will show up there, and you won’t need to do anything else outside the class:

263665-4.png

And normally you would update this sort of stuff in the constructor, but the widget doesn’t exist there yet, so you can’t access it until post begin play.