Changing Static Mesh Instance during runtime

Hey all, so im setting up a grid based system and using static mesh instances to make up the overall grid. To put it simple, im wondering if it is possible to change one of these instances when the player clicks on it?
(For example all the squares are grass tiles, when the player clicks one it turns into a dirt tile)

LineTrace will get you the Instance Index (from HitItem), with that you can do a GetInstanceTransform, RemoveInstance and AddInstance with the new instance you want. Do that works for you?

yeah i tried this but it dopesnt seem to work for me, it runs fine but nothing seems to happen :confused:

cant say anything from that screenshot, but my guess is that you are getting worldspace and if thats it, you need to use add instance World Space

You need to use an ‘add instanced static mesh component’ for each type of square tile you plan on using. You then use ‘add instance’ to add another one of those instances.

If you want to change the square when you click on it you will need to do a line trace or similar to get the component transform and store it. Then remove the instance that you get from the trace and add a new instance of the type you want to change it to using the transform from the original.

I hope this helps.

all my pount and click actions are in the camera Blueprint. All my grid generation is in its own Grid Blueprint. would i use ‘add instanced static mesh component’ in my grid bp or camera one? so far in my grid bp i have two instanced static mesh components.

You will want to put the add instance static mesh component to your grid blueprint.
Here is a video that shows you how to chop down a tree during runtime on the instanced foliage system. It will be the same sort of thing that you are after but instead of replacing the hit instance with a blueprint actor you replace it will the other instance.

I hope this helps.

If you are planning on doing that tutorial, instead of doing a branch for each type of instance you got i would make an interface call and make it output the mesh, id or whatever identifies the object just hit, then work with that (if you retrieve the id, a simple Select int should work)

Sorry but i still cant get my head round this at all, ive tried adding in Add Instanced static mesh within grid but its still not happening. I can locate and delete the current instance under the mouse no problem, but adding new instances during runtime isn’t working for me, there is nothing spawning :confused:

have you checked that its really not spawning? if you are setting the position wrong, it might just be out of your side. check on your World Outliner if its really not there

2 Things:

  1. Please post if you are attempting this on multiplayer or not
  2. Did you mark the instance as “dirty” for a redraw? :slight_smile:

Just offline single player, i’m not sure what you mean by marking the instance? Ive checked the outliner and simplified the grid down to 2x2 to check for any new instances but cant see any.

Can you please post some screenshots of your setup and we might be able to see the issue.

sure, so this is my grid blueprint, this all works fine and in the construction script it generates instances of grass tiles and a few tree tiles.

now my camera pawn that deals with mouse controls, when i left click its grabbing the hit result from the mouse position and setting index, component and transform.

finally im removing the instance that was hit (This all works fine) but the final node doesnt seem to add anything. Ive tried a few variations including “add static mesh instance” but with the same results.