# RTS setup a static mesh switch with a button

**URL:** <https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254>\
**Category:** Asset Creation\
**Tags:** keybindings, unreal-engine, UE4, question, Blueprint\
**Created:** [November 25, 2018, 1:09am UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254 "2018-11-25T01:09:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![PerCat](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/percat/32/479573_2.png) [@PerCat](https://forums.unrealengine.com/u/PerCat)\
**Post date:** [November 25, 2018, 1:09am UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/1 "2018-11-25T01:09:58Z")

</div>

So I have an rts project I’m working on and I can click a gui button and spawn a static mesh that follows the mouse cursor where I then click to spawn it and it builds over time and I’m trying to figure out how to make it so I can hit a button on the keyboard and the static mesh will switch to a different one.

Like say I have house variant 1 selected and then I hit e and it switches to house variant 2 which will then play it’s blueprint command to build when I place it. And then if desired hit e to cycle through or q to cycle previous.

Any help appreciated.

---

<div class="post-metadata">

**Author:** ![PerCat](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/percat/32/479573_2.png) [@PerCat](https://forums.unrealengine.com/u/PerCat)\
**Post date:** [November 26, 2018, 3:23pm UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/2 "2018-11-26T15:23:46Z")

</div>

Thank you man. Gonna try this tonight after work.

---

<div class="post-metadata">

**Author:** ![Detilium](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/detilium/32/985007_2.png) [@Detilium](https://forums.unrealengine.com/u/Detilium)\
**Post date:** [November 26, 2018, 3:45pm UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/3 "2018-11-26T15:45:24Z")

</div>

Sure, no problem. Let me know how it goes.

---

<div class="post-metadata">

**Author:** ![PerCat](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/percat/32/479573_2.png) [@PerCat](https://forums.unrealengine.com/u/PerCat)\
**Post date:** [November 26, 2018, 4:28pm UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/4 "2018-11-26T16:28:24Z")

</div>

Okay so I understand this pretty well but this is my fault I didn’t write my question good enough. Basically my blueprint for each building looks like this.

 ![260483-screenshot-35.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/4/a/74a79f3670e0dd76f9c581be12d37c260367c87d.png) And they are all in a parent child relationship so I’m doing most of my blueprint scripting in the “building master” which from there the buildings are separated out.

building master is a parent of house master so. Building master\>housemaster\>wood house\>forest wood house variants\>(individual bps) like fwhv1, fwhv2, etc…

And so I’m having trouble with this particularly cause I really don’t understand how I would tell it to switch to an entirely different bp with just a keystroke.

Thanks for your help thusfar.

---

<div class="post-metadata">

**Author:** ![Detilium](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/detilium/32/985007_2.png) [@Detilium](https://forums.unrealengine.com/u/Detilium)\
**Post date:** [November 26, 2018, 7:57pm UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/5 "2018-11-26T19:57:47Z")

</div>

_Editing the answer since you weren’t just speaking of static meshes, but actual actors instead._

What I’d do, is to create a struct with these variables. The struct only needs two variables: `StaticMesh` (a static mesh reference), and `ActorClass` (a class of type `ForestWoodHouse`). With this struct you can still just change the static mesh of the house ref, but when you actually “place” the house, you’d be able to grab the actor class from the struct, and spawn that actor.

**Here’s the struct I made**

 ![260511-tmp1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/4/c/74c306f3d93bb8e19739be8c15ac40738f707948.png)

First of all, you need to change the variable type of the `Variants` variable. Instead of an array of static meshes, you change the type to an array of the struct type you just made. I called mine `STRUCT_Variations`.

![260512-tmp2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/b/2/2b21fdb03c9695f85452268c6d2b9e63d921de30.png)

Now just change how you retrieve the static mesh. So instead of retrieving this directly from the array, you need to split the struct to gain access to the static mesh. Here’s that implemented:

 ![260513-tmp3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/1/c/41c2c6a347d0cc18748b996df320286391eb9de1.png)

Now, whenever you wish to construct this certain variation house that you’ve chosen through the use of “Q” and “E”, you can spawn a new actor of the current class that you’ve chosen from the struct. Here’s an example (_I’m just using the “ENTER” key for this example to spawn the actor_):

 ![260515-tmp4.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/3/2/332414f0a2e27b7ce68965a1397dd5934adc351f.png)

I don’t know if you’re using some sort of global ghost constructable blueprint, but if you’re not, you’ll have to destroy the `HouseRef` actor after spawning the variation actor, just like this:

![260516-tmp5.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/a/1/fa1f19edfd43899aaf247cff31590885cf9415ed.png)

I hope this guides you towards a sustainable solution 🙂

---

<div class="post-metadata">

**Author:** ![PerCat](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/percat/32/479573_2.png) [@PerCat](https://forums.unrealengine.com/u/PerCat)\
**Post date:** [November 27, 2018, 5:56am UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/6 "2018-11-27T05:56:02Z")

</div>

It never ceases to amaze me how incredibly helpful this community is. Thank you for this one man

---

<div class="post-metadata">

**Author:** ![PerCat](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/percat/32/479573_2.png) [@PerCat](https://forums.unrealengine.com/u/PerCat)\
**Post date:** [November 27, 2018, 6:38am UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/7 "2018-11-27T06:38:01Z")

</div>

I apologize in advanced for the noob question but what is the node your using to link the target to the int? i tried dragging off my ghost building ref and doing “length” but it just wants to make a new array for some reason. I apologize again for the noob question.

---

<div class="post-metadata">

**Author:** ![Detilium](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/detilium/32/985007_2.png) [@Detilium](https://forums.unrealengine.com/u/Detilium)\
**Post date:** [November 27, 2018, 6:40am UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/8 "2018-11-27T06:40:56Z")

</div>

No problem at all. It’s the variable called variants on your house ref. You can drag from the house ref to get the variants, and drag of the variants to get the length

---

<div class="post-metadata">

**Author:** ![Detilium](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/detilium/32/985007_2.png) [@Detilium](https://forums.unrealengine.com/u/Detilium)\
**Post date:** [November 27, 2018, 6:19pm UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/9 "2018-11-27T18:19:53Z")

</div>

If this answer solves this issue for you, would you mind marking it as the correct answer. This helps the rest of the community to see that this is a solution 🙂

---

<div class="post-metadata">

**Author:** ![PerCat](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/percat/32/479573_2.png) [@PerCat](https://forums.unrealengine.com/u/PerCat)\
**Post date:** [November 28, 2018, 4:03pm UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/10 "2018-11-28T16:03:20Z")

</div>

Would you happen to know what I’m doing incorrect here. The correct house is spawning when I use the button but it isn’t switching variants yet. ForestWHBP has 2 childs so I’m referencing the parent, is this what is causing the problem? The parent for now just has a plane cube for its meshes and so I’m wondering if it’s possible to default the bp to be the first variant and not the parent. Here’s some screenshots that might help you.

 ![260787-screenshot-36.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/7/c/f7c01fd518c9c6911541fb1fc9686db1b6eced40.png)

 ![260788-screenshot-37.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/3/e/f3ebae90e63ffd95390a4aaca5c2710a31ad3c3f.png)

 ![260789-screenshot-38.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/6/3/463dc6a3cd4630a3e8cc06c83089fc0df44166a8.jpeg)

 ![260790-screenshot-39.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/c/5/ac5a386c5f2d3a1f0cc844f6c4b6aff1da47e051.png)

---

<div class="post-metadata">

**Author:** ![Detilium](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/detilium/32/985007_2.png) [@Detilium](https://forums.unrealengine.com/u/Detilium)\
**Post date:** [November 28, 2018, 4:49pm UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/11 "2018-11-28T16:49:19Z")

</div>

Sure. On your `Forest_Wood_House_BP`, you can set the default static mesh on your `Forest WH Ref` on the event `Begin Play` like this:

 ![260812-tmp1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/1/a/41a54f71713d2859de62323eca91757507432c69.png)

Make sure that your default value for the `CurrentIndex` variable is `0`

---

<div class="post-metadata">

**Author:** ![PerCat](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/percat/32/479573_2.png) [@PerCat](https://forums.unrealengine.com/u/PerCat)\
**Post date:** [November 28, 2018, 5:17pm UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/12 "2018-11-28T17:17:11Z")

</div>

I have everything setup exactly as you do yet the mesh still isn’t switching, I apologize for being dumb man. I’m still super new to this but I can’t seem to figure out why my code isn’t working. Like it’s all compiling correctly yet when I use my keyboard it’s not switching any

---

<div class="post-metadata">

**Author:** ![Detilium](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/detilium/32/985007_2.png) [@Detilium](https://forums.unrealengine.com/u/Detilium)\
**Post date:** [November 28, 2018, 6:41pm UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/13 "2018-11-28T18:41:19Z")

</div>

Looking at your `CreateBuildingEvent`, you spawn the actor, but then destroy it right after it’s been spawned. That means that your Ghost building is not actually of blueprint type `Forest_Wood_House_BP`, it just has the same static mesh as the parent class. If you wish to use this youtube series as a guide, you need to adapt the code to work the way you want it. For this specific scenario, you could add the variants struct array to your ghost building. That does however require you to add the `Variants`variable on the ghost building as well as the `Forest_Wood_House_BP` blueprint.

Luckily, I know this of series that you’re following, so you should just extract the variants array from the spawned actor, and add it as a parameter to your `Spawn` method. From here, you set the new `Variants` array of your ghost building. Hope this makes sense, otherwise just ask further 🙂

---

<div class="post-metadata">

**Author:** ![PerCat](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/percat/32/479573_2.png) [@PerCat](https://forums.unrealengine.com/u/PerCat)\
**Post date:** [November 29, 2018, 5:35am UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/14 "2018-11-29T05:35:04Z")

</div>

So I add a variants variable to both the ghost and the parent bp. Then add it as a parameter to the create building event. But after that I get confused.

---

<div class="post-metadata">

**Author:** ![Detilium](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/detilium/32/985007_2.png) [@Detilium](https://forums.unrealengine.com/u/Detilium)\
**Post date:** [November 29, 2018, 7:31pm UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/15 "2018-11-29T19:31:34Z")

</div>

I’ve given you an example below. This is how you’d create a new variable called `Variants` of your struct type array and set this variable in your `OnSpawn` event.

 ![260909-tmp1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/5/7/057b60314c4f8734c32a0cca28641b1257ad165a.png)

---

<div class="post-metadata">

**Author:** ![PerCat](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/percat/32/479573_2.png) [@PerCat](https://forums.unrealengine.com/u/PerCat)\
**Post date:** [November 30, 2018, 6:16am UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/16 "2018-11-30T06:16:12Z")

</div>

It still isn’t working “Blueprint Runtime Error: “Accessed None”. Blueprint: Forest\_Wood\_House\_BP Function: Execute Ubergraph Forest Wood House BP Graph: EventGraph Node: Set Static Mesh” (the one that sets the default mesh(I have it setup the exact same.))) And the keystroke to switch meshes still isn’t working either.

Here’s how I set it up in the ghost.

 ![260945-screenshot-40.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/f/5/5f56ca5eb8607a6c38bb903c19eff57aa9b64b91.jpeg)

 ![260946-screenshot-41.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/3/8/c381c011265413071e0d656b8e96bb099f524024.jpeg)

---

<div class="post-metadata">

**Author:** ![Detilium](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/detilium/32/985007_2.png) [@Detilium](https://forums.unrealengine.com/u/Detilium)\
**Post date:** [December 1, 2018, 8:12pm UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/17 "2018-12-01T20:12:17Z")

</div>

You have your `Q` and `E` event on your `Forest_Wood_House_BP` right? You need to move that to your ghost machine since you despawn your forest house immediately. Besides, in your second screenshot, you don’t need to set the variants variable, as you do that in your `OnSpawn` event. Simply pass the value from your `SpawnActor`, just as you do with the display mesh and the construction proxy.

---

<div class="post-metadata">

**Author:** ![PerCat](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/percat/32/479573_2.png) [@PerCat](https://forums.unrealengine.com/u/PerCat)\
**Post date:** [December 1, 2018, 9:03pm UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/18 "2018-12-01T21:03:32Z")

</div>

Okay I did that but I’m still getting the accessed none error on the set static mesh for some reason. I tried to do an isvalid check but that is still returning the same error.

Seems I only get the error when I hook up the default mesh nodes.

---

<div class="post-metadata">

**Author:** ![Detilium](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/detilium/32/985007_2.png) [@Detilium](https://forums.unrealengine.com/u/Detilium)\
**Post date:** [December 2, 2018, 10:00am UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/19 "2018-12-02T10:00:59Z")

</div>

I’d suggest that you create a new question here on the site, since this is now a different issue. You initially asked for help with changing the static mesh. You got that help,but now that you’re getting an error, I’d say that’s a new issue, and perhaps someone else could help with that, or at least we could get some better overview of the new issue 🙂

---

<div class="post-metadata">

**Author:** ![ThompsonN13](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ThompsonN13](https://forums.unrealengine.com/u/ThompsonN13)\
**Post date:** [December 3, 2018, 2:15am UTC](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254/20 "2018-12-03T02:15:26Z")

</div>

obviously theres room here for modification to combine it with your own systems and adapt to your needs but it eliminates things such as the proxy meshes that are temporary, though you could still use that as well if you liked and i made another version that did. another thing to note is that instead of having your buildings start their “construction” on begin play, i added in a custom event that tells them when to begin construction in the placement script. you could also try doing all of this with datatables if you were so inclined but they dont lend themselves as well to modular design.

[Next page](https://forums.unrealengine.com/t/rts-setup-a-static-mesh-switch-with-a-button/438254.md?page=2)
