Switch BP Actor at runtime using UMG

Here’s a way to deal with 2) and select a specific “alternate” mesh for each instance:

  1. On the BP_MeshSwitcher, create a variable of type StaticMesh (object ref) called AlternateMesh. This is the variable that will be used to determine what the mesh will change to. Make it Instance Editable and Expose on Spawn. This means you can set its value on a per-instance basis after you drag it into the level, i.e. every instance of BP_MeshSwitcher in the level can have a different alternate mesh:

  1. I am going to implement this such that we can switch back to the original mesh if we want. To do that, we need to store the original mesh asset reference so the BP knows what to change back to. Create another variable of type StaticMesh called OriginalMesh (it doesn’t have to be Instance Editable or Exposed on Spawn). Then on BeginPlay for BP_MeshSwitcher, populate OriginalMesh with the value of the StaticMeshComponent’s StaticMesh variable (Note: I renamed the Static Mesh Component to “StaticMeshComponent” for clarity):

  1. Then set up the “SwitchMesh” event to toggle between the two meshes. I put comments in the graph to try to explain the logic.

  1. Now you can drag multiple instances of BP_MeshSwitcher into the level. To set the original mesh of an instance, select it in the level, then select its Static Mesh Component and choose a Static Mesh for it:

To set its Alternate Mesh, select the Actor node itself (where your AlternateMesh variable is located) and choose some other mesh:

Now when I press the button to call SwitchMesh on all of the BP_MeshSwitchers in the level, they each switch to their assigned AlternateMesh, and calling SwitchMesh again changes them back to the original:

5alt.jpg
image_166152.jpg

Note, this is just a simple way to do it - you could also set things up to cycle over an array of meshes, or have the user specify a mesh, but that would be more complicated.