Announcement

Collapse
No announcement yet.

Removing multiple instances which are referenced by their index

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Removing multiple instances which are referenced by their index

    Hey, I have a problem which is almost funny because it's not really a bug but to find a solution for this is like solving an impossible puzzle

    I have one Instanced Static Mesh Component. And I have let's say 3 instances I want to remove. So it's an integer array with 3 integers, the indexes to the instances. Now I call "Remove Instance" in the loop and the index is the first, second or third number out of the array.

    Now the problem is: The only way to reference an instance is with the index. But after I called "Remove Instance" once, all the instances which had a higher index than the instance I removed will reduce their index by one! So the index reference to the other 2 instances I want to remove in this array is completely worthless because they could reference any instance instead of the instance I originally meant.

    I need this because I do a multi sphere trace and I want to remove all instances this trace hits. I do a For Each loop on the Hit Result Array of the Trace, and every hit result has the index of the instance which was hit, but after removing one of them the reference to all the others are just trash. I would have to do a new trace after removing an instance to get the new index. This is surely not the way it is supposed to work.

    So, do you have a solution for this puzzle?
    Easy to use UMG Mini Map on the UE4 Marketplace.
    Forum thread: https://forums.unrealengine.com/show...-Plug-and-Play

    #2
    I don't know if there is a way to sort the array from high to low because that would solve your problem. I'm using transform location as a unique value to find the instances i need, perhaps instead of storing the indexes you could find another unique value to reference your instances.

    Comment


      #3
      Maybe you should have them all have their own components, this way all of them are index 0, and you can keep track of components rather than instances. I'm working on a game like terraria, and all of my instances have their own components, so I don't have problems like this.
      Marketplace Assets

      Advanced Mobile Input: Marketplace Page | Support Thread ――― Easy Input Remapping: Marketplace Page | Support Thread
      Multiplayer Blueprint Chat System: Marketplace Page | Support Thread ――― Closing Credits System: Marketplace Page | Support Thread
      Minesweeper Template: Marketplace Page | Support Thread ――― Maze Creator: Marketplace Page | Support Thread

      Comment


        #4
        If your instances are in each their own Instanced Static Mesh Component then there is not sense to use an Instanced Static Mesh Component at all, you could just use a Static Mesh Component.

        Thommie, how do you reference an instance with the location? There is only one "Remove Instance" node and it only accept's an index.
        Last edited by John Alcatraz; 05-23-2015, 11:59 AM.
        Easy to use UMG Mini Map on the UE4 Marketplace.
        Forum thread: https://forums.unrealengine.com/show...-Plug-and-Play

        Comment


          #5
          I myself put each different instance in their separate folders in the project.

          Comment


            #6
            Originally posted by Mootjuh View Post
            I myself put each different instance in their separate folders in the project.


            I have it working now, but it needs a lot of nodes to make this work. I am basically calculating which instances need to get removed based on which ones got removed before. So if I want to remove {4,2,9,3} in this order, I basically need to remove {4,2,7,2} to remove the correct ones.

            This is how I do it:

            Click image for larger version

Name:	a043a58322.png
Views:	1
Size:	292.0 KB
ID:	1078813

            Click image for larger version

Name:	3a24f6b97a.png
Views:	1
Size:	243.3 KB
ID:	1078814

            And since I need this to work for a trace which might hit different Instanced Static Mesh Components, I had to add a way to combine all the hits in arrays based on which component was hit, I have not yet cleaned up these nodes:

            Click image for larger version

Name:	e37fa79004.png
Views:	1
Size:	403.2 KB
ID:	1078815

            So it's a lot of work just to remove some instances. I hope Epic will make this easier in the future.
            Easy to use UMG Mini Map on the UE4 Marketplace.
            Forum thread: https://forums.unrealengine.com/show...-Plug-and-Play

            Comment


              #7
              I ran into the same problem and I am glad to get behind the problem by this post.
              Thank you!

              Comment


                #8
                In C++ you can sort TArray something like this:

                Code:
                OutHits.Sort([&](FHitResult A, FHitResult B)
                {
                    return A.Item > B.Item;
                });
                and then remove:

                Code:
                for (int i = 0; i < OutHits.Num(); i++)
                {
                     InstancedStaticMeshComponent->RemoveInstance(OutHits[i].Item);
                }
                that's all!
                Realtime Database Firebase | Ultimate Mobile Kit Firebase | Extended Facebook | Universal Mobile Ads | Google Analytics

                Comment


                  #9
                  Originally posted by John Alcatraz View Post


                  I have it working now, but it needs a lot of nodes to make this work. I am basically calculating which instances need to get removed based on which ones got removed before. So if I want to remove {4,2,9,3} in this order, I basically need to remove {4,2,7,2} to remove the correct ones.

                  This is how I do it:

                  [ATTACH=CONFIG]40750[/ATTACH]

                  [ATTACH=CONFIG]40751[/ATTACH]

                  And since I need this to work for a trace which might hit different Instanced Static Mesh Components, I had to add a way to combine all the hits in arrays based on which component was hit, I have not yet cleaned up these nodes:

                  [ATTACH=CONFIG]40752[/ATTACH]

                  So it's a lot of work just to remove some instances. I hope Epic will make this easier in the future.
                  This is very impressive. Thank you, I was thinking I would have to invent this myself. You saved me like a day at least.

                  Comment

                  Working...
                  X