Allow Changing Texture and Mesh on a Structure

From ARK Modding Wiki
Jump to: navigation, search

In this guide we will go through the necessary steps to allow changing a structure's mesh and/or texture using a multi-use menu. The resulting structure will also save these changes to persist over server restarts and properly replicate them to all users.

Before starting this guide make sure you have a structure set up and ready. Make sure you have a way to spawn and place it in order to test if it works.

Step 1: Setting up variables

In order to properly save any changes users make over server restarts you will need one variable per property that will change. In our case we will need one variable to identify the mesh, and one to identify the texture. A few different types could be used, but in order to keep the save game small and allow for efficient replication we will use one integer variable per property. Side Note: You could definitely use a byte variable in order to save even more space, but I am quite sure that UE4 will pad this to 4 bytes anyway. If you do happen to know how this is treated internally, make sure to update this article!

To finish this step create two integer variables on your structure. Let's call them TextureId and MeshId. Set both variables to RepNotify and check the "save game" checkbox as seen in the image below.

Variable Settings for Dynamic Structures.png

Step 2: Preparing GetMultiUseEntries

If you have never worked with the MultiUse Menu in ARK make sure to get familiar with the basics before proceeding, so you can actually understand each step. In this part we will prepare the menu entries that allow users to select their preferred mesh or texture. To show this off we will create two texture entries and two mesh entries. Before starting to edit the graph open the Defaults tab and check the "Blueprint Multi Use Entries" option. Without this your entries will be ignored. Now search for the GetMultiUseEntries function in your Graph tab, right-click it and choose implement. Finally create a graph similar to the one linked below.

Blueprint Graph: https://blueprintue.com/blueprint/oln3vk50/

Notes:

  • Make sure to choose a unique Index for each entry.
  • In this example we are using the TargetingTeam (that means the tribe) to determine if a user is allowed to see these menu entries. Please adjust this depending on your requirements.

Step 3: Preparing BPTryMultiUse

We have already set up showing the entries, not it is time to handle when a user uses one of them. Like in the previous step, search for 'BPTryMultiUse and implement it, then follow the graph linked below to create your own. You will notice we are only setting our id and not doing anything else - don't worry, the actual magic will be in another graph. Please note that in many cases you will need additional logic here - for example if some of your meshes only work with some of your materials. In that case you need to make sure to update them accordingly.

Important: Set the "Multi Cast" flag when setting the texture and mesh ids, otherwise the changes will not be forwarded to the client.

Blueprint Graph: https://blueprintue.com/blueprint/8udykxsv/

Step 4: Preparing the Magic Event

In this step we will create an event that will set the proper mesh and texture based on our texture and mesh ID. First, open the "Event Graph" on your Structure and right click -> add Event -> custom event. I named this event "SetupVisuals", choose a name that fits your purpose. This event does not need any parameters or special settings. Take a look at the graph below to see an example graph and set it up to fit your purpose. Note how we use a switch on our ID to determine what changes to make, and the set static mesh and set material nodes to actually change how the structure looks.

Blueprint Graph: https://blueprintue.com/blueprint/jt10_9un/

Step 5: Setting up the Begin Play Event

This is very simple - just add begin play to your event graph, add a delay node with 0.2 and then call the event we created in step 4.

Step 6: Setting up the RepNotify

This is basically the same as the Begin Play Event, minus the delay. Simply call the event we created in both of the On Rep functions that the engine automatically created for you.

Example Project

You can find an example project including all source files here: https://github.com/taotsetung/arksources/tree/master/DynamicWall

Done!

That's it - users can now select a texture or mesh to use, it properly replicates to all clients and gets stored over server restarts.