I’m trying to manual place instanced Static Meshes in my scene. I see a lot of information on randomly doing this through spawning, but I want to be able to have control of where each mesh is placed. Am I over thinking this or is this complicated. I’m placing rocks around a scene and want them to be instances but I’m going to rotate them in different ways so they look more random. Please help with any information possible.
a other user posted this
Add StaticMesh (with selected mesh).
Create an InstancedStaticMeshComponent variable and Set it using the Return Value on the Add StaticMesh node.
Add Instance, with a Target Input of your InstancedStaticMeshComponent variable and a transform of wherever you want the instance to spawn.
You add the static mesh to get it in the level so it can be copied(not sure why this is needed but it is).
Can anyone show what this blueprint would look like? I tried it but can’t get it to work. thanks
Thanks Zeustiak, anyway you could upload the blueprint. Still kinda confused. What is being plugged into the AddStaticMeshs? and what is feeding into the switch? Sorry, I’m REALLY new to this. Thanks for the help!
What leads to the AddStaticMesh, is irrelevant. You just have to execute it somewhere. It can be the first thing you do in your blueprint(as it is in mine).
Make sure that the blueprint is in the level or that it will be spawned there at some point. You can just drag it from the asset window into the preview pane for testing. Also make sure you select the AddStaticMesh node, go in the details panel, and set which mesh it is adding.
Nevermind the switch, that is just how I determine which of the 4 instances to spawn in the world. You just need the transform, the variable that is set to a mesh, and the add instance node.
And once this is done, i can just grab the blueprint and place in scene and it should work as a instance?
Thanks for the help! Seems to be working…though I’ve done some testing and have some weird results. So I copy about 250 instances and my framerate is around 100fps. When I copy another 250 it drops to 60fps. Is this just my hardware buffer filling up, or am i doing something wrong with the instances. Also in one of your post I saw you made hex patterns with instances…I would love to know how to do that. Thanks again!
Are you copying only the Add Instance node? You only need to add the static mesh once, and then you can forloop on the add instance to spawn however many of them you need.
I don’t see lag until I generate maps with 20K hexes and maybe up to a hundred thousand instanced trees. 500 instances shouldn’t be hitting you very hard.
For my hexagons I just took a cylinder brush, made it 6 sided, made it the size I wanted, and then turned it into a static mesh. Then I lined a few hexes up in the viewport to get the distances between hexes and used that info to spawn everything.
i’m just taking that blueprint and dragging it onto a black floor and just holding down ALT and copying them…I need to be able to place individual pieces, not just randomly placing them. Does the blueprint i posted look right?
Could you maybe show how to do this given my current Blueprint? Thanks for all your help! I really really appreciate it!
Ok, for each copy of that blueprint you are getting a draw call on the static mesh it is spawning.
The reason instancing saves performance is because draw calls are limited by only have 1 mesh that is then copied without the same overhead.
So if you have an instanced mesh, say a Tree, you want all of those trees coming from the same blueprint. You could put other instances in other blueprints, but that really depends on what you are doing.
I see so one Blueprint would need to spawn all the meshes. Is there a way to control each instance once they are spawned? Like say i have 100 rocks spawn. Then move them around and store that position for a layout. Or does instancing only work with random placement?
I’m also not sure how to make 100 rocks spawn either. Sorry I’m sure this is painful to answer, but I’m really very new to this.
You don’t really have per instance control in that manner. You notice that the Add Instance does not have a blue output which with most spawn nodes would give you access to whatever was spawned.
What I do with my map is respawn the entire field of instances. Clear instance, then add them all back in. This is pretty much instantaneous even for thousands of instances. There is probably a limit though, so you will have to see how it fits your needs.
Basically you want to store the vector/transform and any other information about that instance such as “Rock # 5”. Then you can call on that information whenever you want to alter it and replace it.
So if you look at my maps, I store each bit of information about each tile in an array(1 array per type of information). The sea level, precipitation, elevation, etc, etc. Then when I want to change a desert to a plains, I update the precipitation information, then re-instance the entire map.
It can get pretty complicated, but you can work your way up bit by bit.
Start by making an array that stores the vectors of each rock. Figure out how to spawn all your rocks using that array. Then another array that mirrors the vector array, but with Rock information. Then another array with a different set of information, etc.
You are going to use loops of some kind. You can start with a ForLoop to say put X rocks on the field and increment each one’s transform by X/Y.
Then later on you will probably use ForEachLoop to take an array and do the same thing, but for each rock that you have stored in the array.
Just start small and build up.
woah…well that is way over my head. Guess I will need to learn more about Blueprints before trying to tackle this problem. If you get a chance I would love to see one of your blueprints, might be the best way to see how to do it. Thanks for all the information:)
if i wanted to add 100 random rocks, what would i need to do to my current blueprint?
I know you run a forLoop, but i’m not sure what connections i have to make to make something like that work…do i run it out of the AddInstance node? And what do i need in the loop Body?