How to Dynamically create new instanced static meshes?

I’m trying to create multiple dynamic meshes dynamically. Right now the first mesh that gets chosen is the one that is being used. So it seems like the “Add Instanced Static Mesh Component” only works once? I know that it is only one mesh per Instanced static mesh, but isn’t it possible to create multiple, and store the different ones in an Array?

Blueprint:

An ISM component can have 1 Static Mesh, which can then be instanced via Add Instance (top of pic):

You can dynamically add add an ISM component, set its Static Mesh and instantiate it via Add Instance (bottom of pic). A single actor can have any number of ISM components (added manually or dynamically). Each ISM component can have any number of instances of the static mesh its component was assigned.


You can hold ISM components and their instances in arrays:

  • above, an array of ISM component would be of ISM component type.

  • below, an array of instances would be of int type:

1 Like

You’re on the right track, but to actually add the instances, you need to use something like AddInstanceWorldSpace.

342679-ezgifcom-gif-maker.gif

Hello! Thank you for answering. This I already know, maybe my question wasn’t clear enough. Thing is that I want to store Multiple instanced static meshes in an Array, to then use the add instance on the chosen array.

The first picture I posted is inside the “Create Instanced Static Mesh” function seen in this picture. You can see here in the new picture that I try to spawn different instances depending on the Block ID using the Array. Here is the result in the world.

Yes, it’s just the same process, except you just need to set the static mesh in blueprint, rather than in the details.

I used this process ( with HISMs actually ), to do this:

342680-hism-spawner.gif

It’s too small to see any of your BP. What are you having a problem with?

So my main code goes

and PlaceHISMInstances starts with

and then after messing around with a lot of transforms:

This is just because you can’t place HISMs in one go, because of a bug. So you have to place them, then transform them.

I did, it’s still too small :slight_smile:

Ah, can zoom in, it’s ok :smiley:

Not sure what’s going on here

342724-screenshot-5.jpg

You explicitly mentioned ISMs? No wonder it got moderated :>

I’m assuming this

342725-screenshot-6.jpg

is reading from an array of ISMs, not ISM instances?

( because I see you make the ISM, but I don’t see it go into the array ).

Oops, sorry :smiley:

If you’re seeing instances, but not from the rest of the array, somehow I guess, you’re not access the rest of the array for some reason.

Try cutting it right back to basics. Just put a couple in an array and instance them.

And you get an error? Then index 1 isn’t in the array?

I might know what your problem is.

Put this on the start:

342726-screenshot-7.jpg

You can open the image in a new tab to see it. I’ll look over your code and try it out asap, will get back to you!

Hehe, that is just a bug with the lines, don’t worry about it cutting off

Hmm, I’m not sure why it won’t find the right index. I now put manually inn 0 and 1 in the index on each function that creates a new instance.

I’m creating this on begin play luckily! So no need for it atm. Thank you again :smiley:

I have looked at the wrong place for the problem. Sorry, haha :smiley:
The problem was that the code that checked if it already existed was wrong.
This was how it was.

This is the fix!

I really appreciate that you took the time to try to figure out the issue!

I think you’ll find you also need the CLEAR :wink:

Glad you figured it out…