# How to remove instance static mesh when the player collides into a instance static mesh?

**URL:** <https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014>\
**Category:** Blueprint\
**Tags:** unreal-engine, Blueprint, question\
**Created:** [December 22, 2022, 3:33pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014 "2022-12-22T15:33:56Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dino\_dragon\_900](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dino_dragon_900/32/604785_2.png) [@Dino\_dragon\_900](https://forums.unrealengine.com/u/Dino_dragon_900)\
**Post date:** [December 22, 2022, 3:33pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/1 "2022-12-22T15:33:56Z")

</div>

HI, I am making a game where the player is moving through the level to get to the end. The player, has to avoid traps, that show the player. I recently discovered instance static meshes, so I made a BP script to layout instance static meshes, to make levels faster.

I have this

 ![Screenshot_20221222_071434](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/7/2/2727dc1b1a5ab940eb34fd741cdad2baf249ab88.png)

---

<div class="post-metadata">

**Author:** ![Mind-Brain](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mind-brain/32/906573_2.png) [@Mind-Brain](https://forums.unrealengine.com/u/Mind-Brain)\
**Post date:** [December 22, 2022, 8:01pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/2 "2022-12-22T20:01:16Z")

</div>

Hey @Dino_dragon_900!

So… this is worded as somewhat of an informative post. What is actually the problem here? (If the problem is what you’re saying in the title, try “DestroyActor” or “EnableCollision” paired with “EnableVisibility” with both set to False.)

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [December 22, 2022, 8:20pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/3 "2022-12-22T20:20:35Z")

</div>

Hi Dino\_dragon,

Try “Element Index” rather than “Hit Item”.

---

<div class="post-metadata">

**Author:** ![Dino\_dragon\_900](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dino_dragon_900/32/604785_2.png) [@Dino\_dragon\_900](https://forums.unrealengine.com/u/Dino_dragon_900)\
**Post date:** [December 22, 2022, 9:53pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/4 "2022-12-22T21:53:47Z")

</div>

I ty that. did not work.

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [December 22, 2022, 10:14pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/5 "2022-12-22T22:14:53Z")

</div>

Have you done this as well?

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/5/9/5595589e1dd57a89108c959bba9750dd734f9ed2.png)

---

<div class="post-metadata">

**Author:** ![Dino\_dragon\_900](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dino_dragon_900/32/604785_2.png) [@Dino\_dragon\_900](https://forums.unrealengine.com/u/Dino_dragon_900)\
**Post date:** [December 23, 2022, 3:15pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/6 "2022-12-23T15:15:30Z")

</div>

yes it effected all of them

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [December 23, 2022, 6:02pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/7 "2022-12-23T18:02:56Z")

</div>

Yes it does affect all of them. If you’re only wanting some of your instances to have collision, you can make a separate InstanceStaticMeshComponent for them and turn it on in there (e.g. coneCol).

---

<div class="post-metadata">

**Author:** ![Dino\_dragon\_900](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dino_dragon_900/32/604785_2.png) [@Dino\_dragon\_900](https://forums.unrealengine.com/u/Dino_dragon_900)\
**Post date:** [December 24, 2022, 5:54pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/8 "2022-12-24T17:54:51Z")

</div>

I like to Onley effect instances that player collides with.

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [December 24, 2022, 5:58pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/9 "2022-12-24T17:58:44Z")

</div>

Yes, just have two “cone” IMSC’s - one with collision turned off and one with it turned on - The one with it turned on will produce collisions when you hit them, the index of the Instance is in “Element Index” pin.

You’re already testing to make sure it’s the player that collides with them - that is correct.

---

<div class="post-metadata">

**Author:** ![Dino\_dragon\_900](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dino_dragon_900/32/604785_2.png) [@Dino\_dragon\_900](https://forums.unrealengine.com/u/Dino_dragon_900)\
**Post date:** [December 26, 2022, 4:46pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/10 "2022-12-26T16:46:50Z")

</div>

what do this look like?

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [December 26, 2022, 11:59pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/11 "2022-12-26T23:59:47Z")

</div>

I think I see the confusion: the Index that is contained in “Element Index” is the Index that’s returned when you create the Instance of the Static Mesh (CreateInstance). You need to remember the indexes of the ones you are wanting to collide with - that’s also the index you will use for the RemoveInstance node…

---

<div class="post-metadata">

**Author:** ![Dino\_dragon\_900](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dino_dragon_900/32/604785_2.png) [@Dino\_dragon\_900](https://forums.unrealengine.com/u/Dino_dragon_900)\
**Post date:** [December 27, 2022, 1:09am UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/12 "2022-12-27T01:09:50Z")

</div>

can you show me the BP script

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [December 27, 2022, 2:12am UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/13 "2022-12-27T02:12:02Z")

</div>

While create an example I saw the problem. Rather than do a Hit Event for the ISMC (it’s returning the other hit object, so there is no instance index on that) you need to process the Hit Event from the other side (e.g. from the player). Also, you were right, it’s the HitItem rather than the ElementIndex:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/b/a/0ba45525d7d53fdf8fd6eb63153fa0b83a779fb6.png)

---

<div class="post-metadata">

**Author:** ![Dino\_dragon\_900](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dino_dragon_900/32/604785_2.png) [@Dino\_dragon\_900](https://forums.unrealengine.com/u/Dino_dragon_900)\
**Post date:** [December 28, 2022, 3:55pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/14 "2022-12-28T15:55:22Z")

</div>

I see the ling trace. Do I pot it in the player o ISMC?

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [December 28, 2022, 5:30pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/15 "2022-12-28T17:30:03Z")

</div>

In the player - it won’t work from the ISMC…

---

<div class="post-metadata">

**Author:** ![Dino\_dragon\_900](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dino_dragon_900/32/604785_2.png) [@Dino\_dragon\_900](https://forums.unrealengine.com/u/Dino_dragon_900)\
**Post date:** [December 28, 2022, 6:02pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/16 "2022-12-28T18:02:20Z")

</div>

got is

---

<div class="post-metadata">

**Author:** ![Dino\_dragon\_900](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dino_dragon_900/32/604785_2.png) [@Dino\_dragon\_900](https://forums.unrealengine.com/u/Dino_dragon_900)\
**Post date:** [December 28, 2022, 7:29pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/17 "2022-12-28T19:29:23Z")

</div>

How do I check if I hit a ISMC to remove that instance

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [December 28, 2022, 7:52pm UTC](https://forums.unrealengine.com/t/how-to-remove-instance-static-mesh-when-the-player-collides-into-a-instance-static-mesh/734014/18 "2022-12-28T19:52:45Z")

</div>

Here’s how I did it:

1. I created a Blueprint (similar to you) with an IMSC and a Construction Script to place some Instances on the Level.  
In that Blueprint I also created a Function called RemoveInstance which accepts an Index as a parameter.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/8/6/a86803923173432b243390b8f0524bdc7513b6bc.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/4/d/14d59abe90ebaf3c49609df613c40ed3ee2cf5c4.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/e/9/9e9f90adcc20f2ebd649dc3dd29fa488e2f26c78.jpeg)

1. In my Player Character I added code to the Tick (this isn’t the best place, just good as an example) that does a linetrace forward testing for Instances - that removes any instances found:  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/f/d/0fd95b7e7c5f7eab5a9b329044551c81370be3ec.png)

That gives the following results:

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/3/c/73c95e903c4bd417eb86b54e66ad3bb2d0cc257f.jpeg "InstanceCollision") ](https://www.youtube.com/watch?v=E57EX206HIM)

You can see that the Index that it finds the first few times is always “0” - that is correct, when you Remove an Instance - the Indexes all shift down by one. Near the end of the video I skip one and you can see the Index found is “1” instead.

If you want more control of the Indexes after removal, checkout Hierarchical Instanced Static Meshes - they do a “RemoveSwap” which replaces the removed index with the last index (stops the others from shifting).
