-
First, open up Unreal Engine 5 and create a new project or open an existing one.
-
Make sure you have a mesh actor in your level that you want to make visible/invisible. You can drag and drop a mesh from the content browser into your level.
-
In the content browser, right-click and select Blueprint Class. Choose Actor for the parent class, and name it something like BP_MeshInvisibleVisible.
-
Double-click on the newly created Blueprint to open up the Blueprint Editor.
-
In the Blueprint Editor, click on the Add Component button at the top left corner. Type "Static Mesh" in the search bar, then click on Static Mesh to add it to the components list.
-
In the Details panel on the right side, you can set the Static Mesh property to the mesh you want to make visible/invisible.
-
In the Blueprint Editor, click on Event Graph tab located at the top middle of the screen.
-
Right-click in the graph and type "1" in the search bar. Select "Keyboard Events > 1" to create an input for the "1" key.
-
Right-click on the graph again, and type "Flip Flop" in the search bar, and select it. This will be used to toggle between visible and invisible states for the mesh.
-
Connect the Pressed pin of the "1" keyboard event node to the Execute pin of the Flip Flop node.
-
Right-click on the graph, type "Set Visibility" in the search bar, and select it. Make sure the target is the Static Mesh Component you added earlier.
-
Connect the A pin of the Flip Flop node to the Set Visibility node. Leave the New Visibility checkbox unchecked (it will make the mesh invisible).
-
Copy and paste the Set Visibility node (Ctrl+C, Ctrl+V).
-
Connect the B pin of the Flip Flop node to the copied Set Visibility node. Then, check the New Visibility checkbox (it will make the mesh visible).
-
Compile (Ctrl+S) and save the Blueprint.
-
Go back to the main editor and delete the original mesh you've placed in the level (if you haven't already).
-
Drag and drop the BP_MeshInvisibleVisible Blueprint from the content browser into your level.
-
Press Play to test the Blueprint. Press the "1" key to toggle the visibility of the mesh.