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…
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.
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.)
You actually dont have to use the Node SetStaticMesh when you set it already in AddISMC. I just marked both methods in my screenshot
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…
ps. your work is awesome!! inspires me.
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
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…
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.
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
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:
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.
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
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 !
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…