static mesh instance how to

hello

i have an actor blueprint that has static meshes inside and a few blueprint codes inside…
and i want to create instances of it, since i will need a lot of it inside the game…

but im not sure if using static mesh instance is allowed with actor blueprint…

and i dont seem to be able to make it work…

1st, i spawn the said blueprint then “add instanced staticmesh component” then “add instance”
but it doesnt seem to work…

and i have a few questions…

1.what are the purpose of the transform in ad instanced static mesh component, and the transform in the add instance…
2. and since the actor im trying to instance is a blueprint, would they work independently?.

like, instance 1 has a different value for variableA and instance 2 has a different value…

actally, what ive been trying to do is, to let the player assemble floors…
player is able to attach floors to an existing floor… connecting them. using sockets… and attach to component

is it possible that when the player spawn different kinds of floors, they are instances…
but the floor blueprint has variables inside, to let them know if they have walls on each 4 sides or a door or a pathway… etc…

i already got them to work… (assemble part)

but when i tried to randomly spawn 500 different kidns of floors…
it impacts the fps…

thats why i want to try to do it with instancing… but i have yet to learn about it…

Have you set the Static Mesh of the InstancedStaticMeshComponent (ISMC)?
like that:

If you dont set a relative transform in AddInstancedStaticMeshComponent it will be placed at 0,0,0 inside your ActorBP. Which in your case is alright i guess.

The transform of “AddInstance” and “AddInstanceWorldSpace” should be more important because it determines the Position of that instance you add.
The first one places the instance relative to the ISMC, the second in world space.

I have used a struct array for that kind of thing.

like that:

I am using it to save and load my instances. It works good as long as you don’t have too many instances.
(While putting together this sample, a much better method came to my mind. it would only require you to loop through ISMCs till you find the equal one and use the TraceHitItem to get the instance. That would reduce the unneccesairy looping massivly. I’ll post an image later)

edit:
Here is another solution that I havent tested.

Make 2 Structs. In the first struct you add the variables you need for each instance. In the second struct add the first struct as an array and another variable as ISMC type.
(I had some problems with StructArrays inside Structs in the past. I don’t know if “SetArrayElement” works without bypassing the problem inside a function.)

wow, this is really helpful . learned alot more about instanced static meshes…

i did try to set static mesh, but still cant get anything to show up…
see attached image.

a floor should appear at x0y0z0 and the other instanced static mesh…

but only the spawned floor appears, the instance static mesh is nowhere to be found…

i stand corrected, it did appear, i just did not look where it supposed to spawn, i was looking at the opposite side…
its working now… :smiley:

now to experiment with it… :smiley:

You actually dont have to use the Node SetStaticMesh when you set it already in AddISMC. I just marked both methods in my screenshot :smiley:

Another thing that seems odd to me is, why do you spawn a floorBP and add a new ISMC inside it.
It looks like you’re going to spawn the same Floor and add a new ISMC for the same BaseMesh every time you click Space.

In my project I have 40+ different Meshes that you can place.
I have all of them already stored (as ISMCs) inside an ActorBP that is already placed in the level before begin play.
[spoiler]

[/spoiler]
So every time I place something it is inside that ActorBP and I don’t have multiple ISMC for the same BaseMesh.
You can download the full source of my project via the link in my signature. Even though it’s quite different it could be helpful

ok, now that i noticed, i am adding a static mesh instance component inside the one i spawned.
that was for the purpose of what they say i need to spawn 1 first before i can spawn instances?..

ill remove that and see what happens…

and one more thing i want to ask…
when creating an actor blueprint.
when i add component, under ‘Rendering’ i can select “instanced static mesh”
so out of curiosity, i created a blank actor blueprint, and added 5 instanced static mesh
a floor, and 4 walls… then spawned a 200 of them.

FPS went down…
i wonder… the blueprint was blank, and the components are instanced static mesh… - confused…

edit:
wait, you were talking about it already - adding ISM inside the actor blueprint…

i will do take a look with what you have and try to learn as much i can with it… :slight_smile:
ps. your work is awesome!! inspires me.

Mind posting a Screenshot how exactly you spawned them?

I have a feeling that you made a thousand different ISMCs (5*200)
Instead of just adding 200 instances to each ISMC :wink:

Happy to hear that :>
Search for “GlobalConstructBP” and “ConstructionComponent” to find the relevant stuff

heres the experimental blueprint with a few instance static mesh inside…

tried spawning 200 of them

and the result. i got 10-15fps
(uploaded to other host. had aproblem uploading at UE forum)

with the add instance in blueprint, i tried adding 5000 of another static mesh, and there was no recognizable drop in fps…

i think because the instance static mesh is inside a blueprint, and spawned 500 of those, so…bam… :o

that incorrect, you are not spawning 200 instances (if you want do that). you are spawning 200 bp actors that contain each one 5 mesh instances.

yeah. that’s why fps went down.
is it possible to make instance of an actor blueprint?

how do i suppose to spawn a blueprint that contains instanced static meshes.
i wanted to preserve the blueprint codes inside them to function…

It is not possible to instance an actorBP (at least to my knowledge), but there are ways to retrieve Meshes, it’s transform and variables.

What kind of code is inside that bp that you want to preserve?

so one way maybe is to spawn just an actor blueprint with codes inside, but blank visually… and save 'its transform data to an array.
then maybe ill have a spawner handler, and spawns all static mesh is is assigned to to the transform datas it has…

but, im not sure how to trigger updates for each instance…
lets say, a wall is destroyed…

maybe get its id, then remove from the array list of the spawner maybe?

  • just rambling ideas here…
    ill see if i can make it work when i get back to working it.

@, code i want to preserve, are maybe just options to change the walls attached to the floor.

but im trying to think of another way to do it.
something that would make use of the static mesh instance…

i created a blank actor blueprint that would store its coordinate and a few collisions
when spawned, it calls the floor spawner that would spawn an instance static mesh

this is the floor spawner blueprint

then to test the struct array to get variables from the instances static meshes
at the level blueprint - when i press L it locates the instance static mesh

then this is the result…
the floor spawner spawned instance static meshes correctly…
but when i point the mouse and press L…
the index always returns 0… so only the first spawned instance with the 0 index passes…

if it worked… the goal was to be able to attach another L type of floor to the one being pointed at…

You did not spawn them correctly. Instead of adding ONE InstancedMesh with 4 Instances, you added FOUR InstancedMeshes with 1 Instance each. Thats why the Hit result always return 0.
You can see that also in your last Image where you print the display name of the Components, they are all different.

You should do it like this:

hmmm…
alright i changed it, it seems to work…
the index are now labeled 0, 1, 2 and 3…

now, the actor name for all instances are the same, even the component name…
how would i be able to identify each instance…

lets say, i would want to spawn an L shape floor at the south socket of the “static mesh floor”.
speaking of socket, would the sockets of each instance static meshes still work?..

ok, so… if yes… each 1x1 square floor i have (above) have 4 sockets… North, west, east and south
now i want to identify the floor (an instance) under the mouse cursor and spawn another L shape floor instance on the south socket…

so ill be using the indexes? since its the only thing unique to all the instances now…

ok lets say it worked…
then i was thinking, how about if i want to delete an instance, a specific floor instance.
still use index for specifying?.. but wont that jumble up the array?

-learned a little more… but it got more confusing… :rolleyes: hehe

Ok we reached a point where if I tell you anything more, you will just be more confused :smiley:
I think so because there are some aspects that we talked about that you misinterpreted
and it’s hard for me to explain them without confusing the heck outta you xD

Anyway…

I thought you can retrieve sockets like in the nex pic but this is actually wrong. It does not give you the correct transform for the instance.

One way to get it right is to spawn a StaticMesh temporary at the Traced instance transform (set invisible, no collision) and destroy it afterwards. (you could also add a SM inside the BP, set the Mesh and transform when needed and just set Mesh to none instead of destroying it)
like this:

get nearest socket function: (all variables local)

Haha good catch. It came to my mind when I was modifying my own SaveStruct. I am implementing it right now actually.
The solution should be easy if I havent overlooked something.
If you have 10 Indices and you remove Index 3, you have to move all other Indices that are >3 -1 down. Meaning Index 4 will become Index 3, Index 5 becomes 4, and so on…
I’ll post an image later.

@ jumble array… i experimented, it seems that when you remove instance, the lower array index moves up…
so in 0,1,2,3 and you remove 2, the 3 will become the new 2, index 0 and 1 is untouched…

yep, you got it. :smiley:

anyway, ill look up your recent post, and see if i could experiment and play with it… see if i could learn something from it.

  • yeah, im really confused… but heck, we all do, just have to break the barrier, someday ill get it…
    good luck to all of us :smiley:

thanks for more info … i tried to check your project, but i got more confused…
distracted by all the other datas… but man… your work is very impressive!!

got it to work…
at first the get nearest socket was not working… it would always spawn the instance on the SOUTH side…

after analyzing, i just need to set the default value of the [smallest distance] to 1000

now i can connect floorplans to each other with the nearest socket the mouse click…
cheers ! :smiley:

now im experimenting is how to delete the instance under the mouse cursor…
and having some sort of green if placeable and red if it overlaps another floor…

with the instance deleter…sometimes it works, but sometimes other instance get deleted.
must be because of the array jumbling…

Forget to mention that :rolleyes:

About the deleting.
It should never delete the wrong instances if you use the CastoToISMC and the Integer HitItem from the trace with RemoveInstance.

Something in your struct must be wrong.
Looking at the Image from yesterday of how you add things to the struct, looks odd to me.

Have you changed something since then?

hmm, i have not change anything yet…
but, somehow, it’s working perfectly fine now…
it deletes at what im pointing at…

i think the array got jumbled up because i had some experimental spawner placed before, now that i have deleted it.
it seems to be working fine now…