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

**URL:** <https://forums.unrealengine.com/t/how-to-get-the-reference-to-a-ui-wiget-spawn-within-an-actor/440331>\
**Category:** UI\
**Tags:** casting, expose-on-spawn, unreal-engine, UI, Widget, question, Blueprint\
**Created:** [December 30, 2018, 7:58pm UTC](https://forums.unrealengine.com/t/how-to-get-the-reference-to-a-ui-wiget-spawn-within-an-actor/440331 "2018-12-30T19:58:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aGrumpyKoala](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@aGrumpyKoala](https://forums.unrealengine.com/u/aGrumpyKoala)\
**Post date:** [December 30, 2018, 7:58pm UTC](https://forums.unrealengine.com/t/how-to-get-the-reference-to-a-ui-wiget-spawn-within-an-actor/440331/1 "2018-12-30T19:58:39Z")

</div>

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

 ![263656-bookspine-3dwidget-2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/9/4/9940d42a46e563f1d7d02e77da692160a9d0ffca.jpeg)

Am I am trying to update the book title value.

 ![263659-masterbook-system-actor.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/2/c/b2cb2852a5d3df76934dc0624ab88f0490aded82.jpeg)

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

 ![263661-bookspineui-2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/8/d/78d3702966347efae33d24a6c16f936777412d4e.jpeg)

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

Thanks

---

<div class="post-metadata">

**Author:** ![Evigmae](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/evigmae/32/1187349_2.png) [@Evigmae](https://forums.unrealengine.com/u/Evigmae)\
**Post date:** [December 30, 2018, 8:04pm UTC](https://forums.unrealengine.com/t/how-to-get-the-reference-to-a-ui-wiget-spawn-within-an-actor/440331/2 "2018-12-30T20:04:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Evigmae](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/evigmae/32/1187349_2.png) [@Evigmae](https://forums.unrealengine.com/u/Evigmae)\
**Post date:** [December 30, 2018, 8:17pm UTC](https://forums.unrealengine.com/t/how-to-get-the-reference-to-a-ui-wiget-spawn-within-an-actor/440331/3 "2018-12-30T20:17:52Z")

</div>

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.

 ![263662-0.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/2/3/f23ee3481750ac8b88bab7fa922e8f43d09dff34.png)

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.

---

<div class="post-metadata">

**Author:** ![Evigmae](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/evigmae/32/1187349_2.png) [@Evigmae](https://forums.unrealengine.com/u/Evigmae)\
**Post date:** [December 30, 2018, 8:20pm UTC](https://forums.unrealengine.com/t/how-to-get-the-reference-to-a-ui-wiget-spawn-within-an-actor/440331/4 "2018-12-30T20:20:58Z")

</div>

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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/8/4/d842a2a4a3043d0dac3cd401b8ba43653cd34d83.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:

 ![263664-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/6/b/96b07fe75b272b05de59f4e362baf6cb115a6006.png)

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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/4/8/848b4f71c911db198ae69a8823d613cdf49a8ad2.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.
