Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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

alt text

Am I am trying to update the book title value. alt text

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).

alt text

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


Product Version: UE 4.17
more ▼

asked Dec 30 '18 at 07:58 PM in Blueprint Scripting

avatar image

14 1 2 3

avatar image Evigmae Dec 30 '18 at 08:04 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

alt text

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.

0.png (115.8 kB)
more ▼

answered Dec 30 '18 at 08:17 PM

avatar image

1.7k 8 3 8

avatar image Evigmae Dec 30 '18 at 08:20 PM

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

alt text

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:

alt text

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:

alt text

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.

3.png (43.0 kB)
1.png (93.1 kB)
4.png (27.3 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question