No announcement yet.

Update Instance Transform Troubles (at Runtime)

  • Filter
  • Time
  • Show
Clear All
new posts

    Update Instance Transform Troubles (at Runtime)

    I'm new to UE4 and currently exploring Bluprints, which has been lots of fun so far.
    Today I started looking into instances and encountered the following problem:

    In the Construction Script I'm creating a row of Instances which works fine.
    Click image for larger version

Name:	ConstrucionScript.PNG
Views:	1
Size:	227.6 KB
ID:	1162246

    In the Event Graph I then try to rearrange the Instances which, unfortunately, doesn't yield any results.
    Click image for larger version

Name:	EventGraph.PNG
Views:	1
Size:	198.5 KB
ID:	1162247

    (This is a simplified version of the setup to illustrate my problem)

    If I use the Update Instance Transform Node in the Construction Script it works fine.
    I would very much appreciate any hints on what I'm doing wrong and ideas on how to make it work.
    I'm running Unreal Engine 4.9.1

    Thank you all in advance!

    First you are storing instanced static mesh, and not pointers (ids) for instances of static meshes.
    "instanced static mesh" is like mold for instances, engine uses it to copy mesh and material over to instances that are in level. So store ids of instances that you spawned instead of mesh that they are copied from.

    Well, it looks like you store right value, but you store all in single variable, use array instead and add to array.But I am leaving above comment/paragraph anyway, it is common mistake to store wrong pointers.
    So add those values to array instead storing them all by "set" value node. Before you start adding to array it is good habit to add "Clear array" node, even if you do not need this in construction script. Saved headache for me few times.

    Then you have foreach item in array, it will loop trough array, and you do not need to worry about indexes

    And last mistake you did is wrong index in for loop where you read values. You connected index value to first index and last index is empty. First index should be 0 and that index you calculated should be connected to last index pin. But this irrelevant if you use foreach in array.

    Short version.

    in first graph, make array of static mesh instance (you have single variable there)
    instead of setting that variable use clear array node
    in for loop create instance and add its id (pointer) to array

    in second graph use for each in array, instead of simple for each loop.
    Last edited by Nawrot; 10-02-2015, 10:29 AM.


      Hi Nawrot.
      Thank you for your quick response!
      Using the For Each Loop solution with arrays is a great best practice tip; good to know

      I'm afraid that either I don't understand everything correctly, or the problem is a bit more tricky.
      Let me specify:

      If i move the nodes from the Event Graph to the Construction Graph it does what I want it to do (so the Blueprint in the screenshot below yields the correct result):
      Click image for larger version

Name:	ConstrucionScript_2.PNG
Views:	1
Size:	427.2 KB
ID:	1088595

      The problem is that i want to animate the instances with e.g. a sinus or another function. This is why I need to adress the instances on runtime.
      But the same configuration of nodes doesn't work in the Event Graph.

      I didn't store the Instanced Static Mesh Component in an array because I only have one.
      And when I tried, I couldn't feed it to the Add Instance and Update Instance Transform nodes anymore.

      Maybe you could clarify the bit about the array?
      Thank you for your time!


        Thank you, for your time.
        I found the solution:
        I had to set the "Mark Render State Dirty" value of the "Update Instance Transform" Node to true.
        It works now


          Yeap, you have to mark it as dirty it at the end of your update - usually on the last item of the loop.
          Youtube Channel


            What do you mean by "on the last item of the loop."?
            I simply checked it on the node.
            Would it be better performancewise to set the value true only on the last iteration of the loop?


              For the mark dirty you can get the length of the array and check if the current index == array length - 1 (since the length includes zero) and just plug that into the mark dirty and it will be true for the last 1.


                Hi ZoltanJr.
                Thank you!
                I also thought of that way to do it
                I just don't understand the benefit in contrast to simply having it checked on the node.
                In my setup I didn't expirience a noticable difference in performance.
                Anything going on under the hood I should be aware of?
                Thank you very much!


                  Instanced static meshes are designed to have thousands, tens of thousands, hundreds of thousands etc etc instances. So you just having 10 of them is not really going to make any difference, but if you had 10 million of them it will make a huge difference trying to do them all within the loop rather than waiting for the loop to end and then doing it.


                    Thank you very much for your time and thoughts
                    Have a good day!


                      glad to see other people spending their weekend figuring out the exact same thing lol. now to get it working in c++. something like instancedstaticmesh.bRenderStateDirty=true, but thats not working..


                        instancedstaticmesh->MarkRenderStateDirty() worked!