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

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

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.)

Hi Dino_dragon,

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

I ty that. did not work.

Have you done this as well?

image

yes it effected all of them

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).

I like to Onley effect instances that player collides with.

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.

what do this look like?

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…

can you show me the BP script

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:

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

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

got is

1 Like

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

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

  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:

That gives the following results:

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).