I am creating location vectors in the construction script through the details panel and storing these in an array.
Now I’d like to be able to place an “editable” mesh at a specific location.
I have no issues to place instanced meshes at the locations.
e.g. place MESH1 at all 5 locations
what I am trying to achieve is place MESH1 at Location 3 and 5 while MESH2 is placed at the others.
Accessible through the details panel
I cant wrap my head around it. I am able to change meshes but always affecting all meshes at once. never a specific one. i have tried different approaches with arrays and switch on
Instanced Meshes share the same mesh data, so it’s not possible to change the mesh of just one instanced mesh. My solution would be to create the number of Instanced Static Mesh components you’ll need, and make an array of locations for each. Another idea would be to create a struct, with a field that identifies which Instanced Static Mesh component to target and a vector, make an array of the type of the mentioned struct. You can then loop of the array and target the static mesh component you need, and spawn an instance at the given location.
Hope that helps. Just let me know, if you need further assistance or if you have any questions.
thanks for your reply!
i knew about instances sharing the same data. As you suggested, I have created all needed mesh components but am still trying to find a solution where I can use the detail panel.
What I am trying to achieve via details panel is:
create six spawn points location (done)
assign type to location eg Type A, Type B, Type C (how?)
assign Mesh A/B/C to fitting location (done)
I think I have an issue with how I am clearing my arrays… looking into it now and I must say: structs are amazing!
I’ll give it another try and will hit you tomorrow, if that’s alright.
After trying some things it is clear that I can’t handle arrays in the construction script the right way.
I have an issue with filling arrays in the construction script the right way
If I don’t clear the array at the beginning, its full of old instances
If I clear the array, I cant change its elements as it is called constantly
tried adding branches to take control with no success
latest try was the following:
fill vector array via construction script which is cleared at the start
pass the data into a struct array containing
vector
boolean isMesh1
boolean isMesh2
I want to use the boolean to define which meshes I want to spawn.
clearing the struct array at start doesnt help as I can’t change the boolean (as clearing is being called all the time). adding a branch didnt help, as changing the boolean added an item to the array instead of changing the input.
(You can right click on that image and open it in a new tab, so you can see it’s contents easier.)
Important things to note:
The type ‘Type’ is just an enum, containing the fields ‘Type A’, ‘Type B’ and ‘Type C’.
The struct ‘Data’ is an struct with a field of type ‘Type’ and of type ‘Transform’ (you can change that into just a vector, it just adds more controllability).
The Map ‘InstancedMeshes’ is of type ‘Type’ to ‘Instance Mesh Component’ (reference)
The variable ‘LocationAndMeshData’ is an array of type the struct ‘Data’
The construction script gets called every time we either change a variable, it’s transform (location, rotation & scale), and with the actor’s ‘Begin Play’ event. Just to make sure the map is correctly populated, we clear and then populate it with the references via their key (type). After that we clear any instance the Instanced mesh components already have, after that we populate the level with the instances at the given transforms.
This is quite possibly not the best solution, but it should work, and it should be rather easy to expand on it. (It’s quite possibly also quite overdone).
wow! Vecherka you are amazing. Didn’t expect you to deliver it on a silver plate.
haha
And thanks to you I am finally understanding how to use maps!
After implementing your solution, I still had the struct array issue as it was cluttered with old data. This time I tried a cleaner solution - see below. I guess it is still improper coding, but it is running without any issues. I have put the blueprints right in your populate level script.