# Toggle widget visibility?

**URL:** <https://forums.unrealengine.com/t/toggle-widget-visibility/485576>\
**Category:** UI\
**Tags:** toggle, actor, controller, unreal-engine, Widget, question\
**Created:** [June 30, 2021, 1:22pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576 "2021-06-30T13:22:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tettey\_Nartey](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tettey_nartey/32/882427_2.png) [@Tettey\_Nartey](https://forums.unrealengine.com/u/Tettey_Nartey)\
**Post date:** [June 30, 2021, 1:22pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/1 "2021-06-30T13:22:52Z")

</div>

To be more precise, Can I get one actor to toggle the visibility of a widget of another actor?

If so, how exactly?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [June 30, 2021, 2:07pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/2 "2021-06-30T14:07:48Z")

</div>

> Can I get one actor to toggle the  
> visibility of a widget of another  
> actor?

- _Another Actor_ creates a widget and stores a widget reference:

 ![342820-screenshot-3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/d/5/1d5e487bfe20d4dde27d87bc383eabf2d4cb99b3.png)

- _One Actor_ changes Visibility of Another’s widget:

 ![342842-screenshot-5.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/f/f/9fffbd0f4173beff8122414068037b8f2d079830.png)

* * *

But I sense your question has less to do with widgets and more to do with actor referencing.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [June 30, 2021, 2:10pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/3 "2021-06-30T14:10:01Z")

</div>

There are so many different ways of passing data between blueprints - you’ll need to very precise regarding _what_ needs getting _where_ and to _whom_ if you need a concrete example.

---

<div class="post-metadata">

**Author:** ![Tettey\_Nartey](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tettey_nartey/32/882427_2.png) [@Tettey\_Nartey](https://forums.unrealengine.com/u/Tettey_Nartey)\
**Post date:** [June 30, 2021, 3:47pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/4 "2021-06-30T15:47:29Z")

</div>

Okay. I have a ship actor. I give it a widget component that is hidden in the game, and I want it’s visibility to be toggled on or off based on that ship actor.

 ![342835-ship-another-ship-with-controlled-widget-hidden-in.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/1/b/21bbec34ee400d67d16f1fe65d6a2dc7d15bb32e.png)

The thing is, as a set up I have the other ships are all children of the one ship I made. Will this be a problem?

 ![342836-ship-main-lock-on.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/d/e/7de2682ff7584df804bb23b4973447794fdabe74.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [June 30, 2021, 4:03pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/5 "2021-06-30T16:03:34Z")

</div>

> I have a ship actor. I give it a  
> widget component that is hidden in the  
> game,

Sure, makes sense.

> I want it’s visibility to be  
> toggled on or off based on that ship  
> actor.

What does it mean?

---

<div class="post-metadata">

**Author:** ![Tettey\_Nartey](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tettey_nartey/32/882427_2.png) [@Tettey\_Nartey](https://forums.unrealengine.com/u/Tettey_Nartey)\
**Post date:** [June 30, 2021, 4:14pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/6 "2021-06-30T16:14:13Z")

</div>

So if I press a button, the HUD should toggle on, displaying the widget component of the other ship, and should toggled off after I press it a second time; hope that’s good enough.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [June 30, 2021, 10:41pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/7 "2021-06-30T22:41:25Z")

</div>

> displaying the widget component of the  
> other ship

Makes sense.

- how many _other ships_ are we talking about?
- Is there only 1?
- If there’s more, how are we selecting other ships?
- how do we know which one?
- how does this other ship come into play? Spawned dynamically or added manually to the map?

---

<div class="post-metadata">

**Author:** ![Tettey\_Nartey](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tettey_nartey/32/882427_2.png) [@Tettey\_Nartey](https://forums.unrealengine.com/u/Tettey_Nartey)\
**Post date:** [July 4, 2021, 8:28pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/8 "2021-07-04T20:28:31Z")

</div>

- Yeah in this case it’s just one ship; would like to add more ships later down the line, but I need to focus on just getting one done first.
- I don’t want the option to select other targets. I think that would make it a bit more complicated to I wanted to start with a simple goal of displaying the widget component of the other ship. So for now, it’s just one.
- I at first thought you won’t really have to know which one to shoot at; just aim and shoot, like in an FPS. So it’s not quite like a Ace Combat or Air combat sim because while I want this for my game, it is not the ultimate goal of the project.
- Ship or Ships are spawned dynamically.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 4, 2021, 9:01pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/9 "2021-07-04T21:01:41Z")

</div>

> Ship or Ships are spawned dynamically.

Wouldn’t that just work then:

 ![343226-screenshot-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/f/a/cfa95aef2b463ce0d98b2a711841480bed0d70c1.png)

Each ship can push data into another ship.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 4, 2021, 9:05pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/10 "2021-07-04T21:05:09Z")

</div>

Or, if you must, create a reference of Enemy Ship in the Player ship and expose it:

 ![343228-screenshot-4.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/b/f/fbfd53043079ec5db22eb2cb06a6f84e7f60113e.png)

---

<div class="post-metadata">

**Author:** ![Tettey\_Nartey](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tettey_nartey/32/882427_2.png) [@Tettey\_Nartey](https://forums.unrealengine.com/u/Tettey_Nartey)\
**Post date:** [July 4, 2021, 9:18pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/11 "2021-07-04T21:18:18Z")

</div>

I’m sorry I’m not being clear enough; I meant to say the widget component is the main obstacle here.  
I already have the ships spawned on the map, plus I know how to spawn them in the game dynamically, So I think I’m set there.

What’s been bugging me is the widget component and getting the other enemy ships to display. on the screen or HUD. I hope I’m not losing you 🙂

also about the second picture, I’m confused … so the player ship is spawning the enemy ship and the enemy ship is spawning the player ship, again???

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 4, 2021, 9:26pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/12 "2021-07-04T21:26:25Z")

</div>

> Ship or Ships are spawned dynamically.

vs

> I already have the ships spawned on  
> the map

So which one is it? Hope you understand my confusion 🙂 These two statements contradict.

* * *

If both ships are already on the map, the communication is trivial:

- create a reference to the enemy ship in the player ship - this way you can access the enemy’s widget

 ![343229-01.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/a/c/1acee6e7f9814f81386427d2bef22dc66fbac4b0.png)

- since both are already in the world, reference them:

 ![343230-02.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/7/1/1715b280adc5543da3608a93874b599e9f02b2dc.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 4, 2021, 9:27pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/13 "2021-07-04T21:27:12Z")

</div>

No, you said that both ships are spawned dynamically… so that’d be the blueprint that spawned them.

---

<div class="post-metadata">

**Author:** ![Tettey\_Nartey](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tettey_nartey/32/882427_2.png) [@Tettey\_Nartey](https://forums.unrealengine.com/u/Tettey_Nartey)\
**Post date:** [July 6, 2021, 2:23pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/14 "2021-07-06T14:23:40Z")

</div>

Okay I tried it but it didn’t work; I will show my setup in few.

Here is my Ship(The Ship I control)

 ![343442-main-ship-controlled-by-player-event-begin-play.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/9/5/f9598164b2e1c0b3c3ecc7060fb11088f4459407.png)

 ![343443-main-ship-controlled-by-player.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/0/5/2056aaff13c94d9de1be692c4dc1fb54a208cce1.png)

I might not need the Sequence Node but I just wanted to see if there’d be any difference.

And here is the Enemy Ship

 ![343444-enemy-ship.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/b/f/ebfa3cd23c466453449593d57fc0a944a658f3a0.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 6, 2021, 9:10pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/15 "2021-07-06T21:10:25Z")

</div>

Not sure why you’re posting all this but I can’t see anything I suggested here.

We’re talking about _a single variable_ that you point at an actor in the world… and you’re done. Once you get it going, you can continue working with the rest.

Perhaps you should consider following what I proposed. Or you did and it does not work? Sorry, but I can’t see the critical bit above. Most of the script you’re showing is just not relevant at all.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 6, 2021, 9:12pm UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/16 "2021-07-06T21:12:53Z")

</div>

Is it Ship Targets? Did you assign the enemy ship from the world? It’s the 2nd pic.

Could you show how you’ve assigned it?

---

<div class="post-metadata">

**Author:** ![Tettey\_Nartey](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tettey_nartey/32/882427_2.png) [@Tettey\_Nartey](https://forums.unrealengine.com/u/Tettey_Nartey)\
**Post date:** [July 7, 2021, 10:50am UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/17 "2021-07-07T10:50:56Z")

</div>

![343494-image-2021-07-07-064955.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/7/d/b7d7bc03dfee3877d6636b61a0ef3a082bad1c54.png)

Yeah I did it like you said and it didn’t work.

and yes the Ships Target is the variable for the other ship.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 7, 2021, 10:58am UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/18 "2021-07-07T10:58:43Z")

</div>

> it didn’t work.

This is not descriptive enough, sorry. If you need help, you _really_ must try a bit harder. Grilling someone for info is no fun at all 😉

So what _exactly_ does not work? Use _Print String_, _Breakpoints_, _Watch_ pin values and use _Debug Filter_ to observe data flow. Did you try any of this? Do you see any warning / error messages in the log?

What is Target Indicator - the enemy’s Widget Component? Do the nodes fire? Is the widget set up correctly?

---

<div class="post-metadata">

**Author:** ![Tettey\_Nartey](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tettey_nartey/32/882427_2.png) [@Tettey\_Nartey](https://forums.unrealengine.com/u/Tettey_Nartey)\
**Post date:** [July 7, 2021, 11:32am UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/19 "2021-07-07T11:32:17Z")

</div>

OMG I did not think of doing the print string part; my bad.

Yes Target indicator is the Widget component for the enemy

All of the other nodes used are not relevant, you’re right.

Okay so I managed to get the widget to display.

The Widget Component Rendering settings had Visible and hidden in Game both set to true, and I think that may have messed things up a bit. I cannot believe this, I feel so dumb.

alt text

Okay so I have one ship to display the widget; and you’re gonna hate me for this because I now want to be able to display the widget component for all the ships currently in the world. Now I realize what you mean by the Communication is trivial.

To do this I assume I’d have to use a for each loop and cast to node, but I know I’d be missing something here.

So I had an Idea, haven’t done anything with it yet but I would like some feedback on this: is it possible to have an actor that spawns a sphere that detects all the actors within the bounds of that sphere? This way I won’t be turning on all the widgets for every ship in the world, only the ones that overlap that sphere that was spawned?

I hope the point was to show me how to do it step by step by simple things first in small increments before getting to the more complex ideas because if so it is working,

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 7, 2021, 11:37am UTC](https://forums.unrealengine.com/t/toggle-widget-visibility/485576/20 "2021-07-07T11:37:33Z")

</div>

> I now want to be able to  
> display the widget component for all  
> the ships currently in the world

If this is really what you need and you really mean all of them then _Get All Actors of Class_ would work well. No casting necessary as this filters it out:

 ![343511-screenshot-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/f/28f73a3494d21c3f4c65adf2efd538c92abfdcea.png)

Select Class first and then connect the Loop.

[Next page](https://forums.unrealengine.com/t/toggle-widget-visibility/485576.md?page=2)
