How to toggle visibility of the mesh when there is a certain value in Spinbox in Widget

Hi, I have a question about how to toggle the visibility of one mesh and display another mesh in its place when there is a certain value in Spinbox in Widget. For example, when I enter 6 into the spinbox in-game it should hide a certain mesh and swap it with another, which I assume is positioned in the same place but was hidden from values 0-6.

Hey @akevorkov

you can do this in 2 different ways with an interface.

  1. Have one ParentActor and 2 ChildActors which change their visibility
  2. Have one ParentActor and 1 ChildActor which changes its static mesh

Let’s say you have your widget set up. You want to do something (here: change the mesh) whenever you change the value. So we use the event OnValueChanged to do something.


This could look like this (you can not copy this directly because GetVis is missing for you, read on):

Here you can see

  • MeshArray
  • Interface Call
  • Using Round to get an integer so you don’t have to worry about fractional digits

The MeshArray contains every blueprint with our interface. We get this array at EventConstruct inside the widget:


The SetValue is used twice to trigger the OnValueChanged event.

The interface call is used to call an event inside those other blueprints. For this (and also the GetAllActorsWithInterface) we need an interface. This can be created like a blueprint inside your content browser with right click, blueprint, blueprint interface. Looks like this (with the event we will need):

To add this interface to a blueprint you open the blueprint and click on ClassSettings.


Now, in the Details panel, you can add your interface:

Mine is called BPI_WidgetMeshCom
This will add an Interfaces tab on the left:
image
With right clicking the GetVis here you can implement the event. I already did this and made the final event for the actors:

So when you change the value of the SpinBox, the event GetVis gets called and sends the ValueIn to all blueprints with the interface we added. Then the value gets compared to a range. For this range I added 2 variables called From and To. If the ValueIn is in this range we set the StaticMesh to visible otherwise to not visible. Also those 2 variables on the left From and To are set to InstanceEditable from the Details panel.
This would give you an actor in the content browser like this:
image
Now you can right click this actor and select CreateChildBlueprintClass:


With this method you can now create as many child actors as you want, set their static meshes and then place them inside your level:
image

There are 2 actors/blueprints, but inside of each other. Now I can select one of them in the viewport or in the outliner and get these input fields:
image
Here I can set the values for which my actors/blueprints get visible/invisible:

Method 2 would contain changing the static mesh instead of changing the visibility of 2 actors/blueprints:


2 actors on the left, 1 one the right:

And here is an example
UE52_ToggleVisibility.zip (88.9 KB)

This is great and thank you for your quick response! I will try it in the next couple of days and will let you know! Thank you again!

1 Like