Placing different meshes in "Instanced static meshes"

I am currently trying to make a script in construct where you can randomly place out a forest within a specific grid (think different types of trees, rocks etc…). It’s working without issues when I have a single instance static mesh but when I try to use multiple it simply selects the first one and makes all other instances the same one.

As you can see here it works without issues when using a single instance

Meanwhile when I try and use multiple meshes:

Looking at the code for the single instance:

And then the code for the multiple instances:

(additionally adding my variables if they are of help)
image
and to clarify the only thing my component has is a single instance static mesh
image

Thank you in advance! :blush:

When you instance a mesh, you get multiple copies of it.

If you want multiple meshes, you need multiple instanced static meshes.

Thank you for the answer!

Got any clues to how i should do this?

1 Like

You need an array of ISMs ( one for each mesh ), and then you make instances by choosing different ISMs.

Tell me if you get stuck, I’ll give you an example, but not at a machine rn…

1 Like

Thank you, I am also not currently running unreal so I will try it a bit later.

I patiently await your example!

Here’s one way you could do it:

I just added 3 instanced sm components, and used a select node to randomly pick one to add an instance to during the loop (or just the first if multiple meshes is false). Add more ISM components as needed, then add pins to the select node and plug them in. Mine is done in a function called by the construction script, but it could be done in the CS itself.

1 Like

I REALLY like how this is looking, seems to answer my question, I only have one nitpick, is it possible to make it so that you can add / remove static instances in the viewport? Since its a bit counterintuitive to make a tool where you have to constantly go in to the blueprints to add/remove more static meshes.

Thanks for the answer!

Sure. If you add meshes in the level viewport, or just don’t want to muck about with the select pins, you could use getcomponentsbyclass and plug that into the addinstances node.

This is from bp example above, just with the get components bit wired in instead of the original select logic.

1 Like

if you are looking to remove a specific instance, theres a function to check overlap (use a box). it returns an index, which you can then use to remove the instance from the instanced static mesh component.
from what i remember its a bit busted but i got it working eventually. its using local space when it shouldn’t or something idk.

1 Like

Thank you so much! This is what I was looking for.

Although I did notice a problem after doing this, It would seem like the instance is run every time anything changes, So once I change the grid size or the seed it creates a new instance on each and every new location without removing the old ones

Currently working on a fix so I will update if I come up with a solution :eyeglasses:.

Something like this, usually means you have to clear an array you’re populating in the script. You need to clear it at the start.

1 Like

This worked perfectly!

image

Now i just gotta figure one of these comments to mark as the solution :thinking:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.