Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

using static mesh instances with blueprints

Hi All!

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

3 Steps.

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

Product Version: Not Selected
more ▼

asked Nov 08 '14 at 01:30 AM in Blueprint Scripting

avatar image

26 12 17 21

avatar image walkinginspace Nov 08 '14 at 08:48 AM

help!!!!!!! please:)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first


alt text

more ▼

answered Nov 08 '14 at 09:22 AM

avatar image

1.8k 131 68 110

avatar image walkinginspace Nov 08 '14 at 12:26 PM

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!

avatar image Zeustiak Nov 08 '14 at 01:15 PM

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.

avatar image walkinginspace Nov 08 '14 at 11:53 PM

alt text

instance.jpg (102.8 kB)
avatar image walkinginspace Nov 08 '14 at 11:53 PM

Is this correct?

avatar image walkinginspace Nov 08 '14 at 11:54 PM

And once this is done, i can just grab the blueprint and place in scene and it should work as a instance?

avatar image walkinginspace Nov 09 '14 at 12:39 AM

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!

avatar image Zeustiak Nov 09 '14 at 01:45 AM

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.

avatar image walkinginspace Nov 09 '14 at 02:02 AM

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?

avatar image walkinginspace Nov 09 '14 at 02:03 AM

Could you maybe show how to do this given my current Blueprint? Thanks for all your help! I really really appreciate it!

avatar image Zeustiak Nov 09 '14 at 02:07 AM

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.

avatar image walkinginspace Nov 09 '14 at 02:28 AM

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?

avatar image Zeustiak Nov 09 '14 at 04:10 AM

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.

avatar image walkinginspace Nov 09 '14 at 02:29 AM

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.

avatar image Zeustiak Nov 09 '14 at 04:12 AM

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

avatar image walkinginspace Nov 09 '14 at 05:05 AM

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

avatar image walkinginspace Nov 09 '14 at 05:37 AM

if i wanted to add 100 random rocks, what would i need to do to my current blueprint?

avatar image walkinginspace Nov 09 '14 at 05:39 AM

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?

avatar image Zeustiak Nov 09 '14 at 06:43 AM

You probably need to back up and figure out what the nodes do before you start asking how you can do various things. Everything you are asking is already in the forums, answerhub, the documentation, youtube, etc.

I would recommend heavily studying all the tutorials available. Follow other people's work, try it on your own, and then if you really can't figure something out ask questions.

avatar image walkinginspace Nov 09 '14 at 07:17 AM

Yep I totally agree:) Thanks for your effort though, I'll get cracking!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question