# How to find which object to cast to?

**URL:** <https://forums.unrealengine.com/t/how-to-find-which-object-to-cast-to/388094>\
**Category:** UI\
**Tags:** hud, unreal-engine, UE4, question, Blueprint\
**Created:** [March 16, 2017, 11:19am UTC](https://forums.unrealengine.com/t/how-to-find-which-object-to-cast-to/388094 "2017-03-16T11:19:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_4c38c8d4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4c38c8d4](https://forums.unrealengine.com/u/anonymous_user_4c38c8d4)\
**Post date:** [March 16, 2017, 11:19am UTC](https://forums.unrealengine.com/t/how-to-find-which-object-to-cast-to/388094/1 "2017-03-16T11:19:34Z")

</div>

Hi, im trying to make a Hud which displays the score. The score is calculated when one of the falling objects (the game) hits the floor created in the level. I am then trying to display the score in the hud but am being unsuccessful. This is the code so far.

 ![130300-ue1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/f/e/3feaa4917b46055263d9e15ca7b5113505027e4d.png)

 ![130301-ue2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/4/5/145d4590af05811b7664ae3fbaf9b66d0d5f9ad5.png)

 ![130303-ue3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/a/6/8a6dcbce6adcc5a6de9720426edb7304442d0149.png)

This next one is the above photo zoomed in ty for anyhelp:)

---

<div class="post-metadata">

**Author:** ![Mosel3y](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mosel3y](https://forums.unrealengine.com/u/Mosel3y)\
**Post date:** [March 16, 2017, 11:43am UTC](https://forums.unrealengine.com/t/how-to-find-which-object-to-cast-to/388094/2 "2017-03-16T11:43:45Z")

</div>

You HUD needs a reference to Cube\_Blueprint, where are you adding the widget to the viewport? And where is the Cube\_Blueprint in the beginning of the game?

You won’t actually need the cast at all if it is a reference to the actor. I’m not sure how you’re doing this, but say for example your Cube\_Blueprint exists in the map, and you adding your HUD to the viewport on BeginPlay in your level blueprint, you could do the below:

- Add a new variable to your HUD, of type Cube\_Blueprint Reference, make it editable and exposed on spawn by clicking these checkboxes:

![130306-cbb.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/8/a/38a3d8df06527a4d93b538a10457b2d81660e35c.png)

- In your level you have Cube\_Blueprint, and you are adding the widget to the viewport in the level blueprint:

 ![130308-ref.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/3/a/23a2cf945acb8eee84627c69d4f7d2076d36939d.png)

- Then back in your HUD widget in your GetText function, you can do this without a cast:

 ![130309-gt.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/7/9/1794ddd17217502c48e8482d112a84fe72bee668.png)

This might not apply specifically to you, but basically, you need a reference to you cube\_blueprint in order to get the score from it. And there’s a lot of different ways of doing this. But if you can avoid using GetAllActorsOfClass, or casts, in your GetText function, that is ideal.
