Announcement

Collapse
No announcement yet.

Get all actors of a class not indexed in proper order

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

    Get all actors of a class not indexed in proper order

    In a loop , I spawn some actors, index them(in their actor blueprint variable). They are indexed right after spawn (in a loop - with a line from the spawn function).
    First time I run the game from editor - accessing these actors with *get all actors of a class* works as it should (properly assigned indexes).
    When I exit the game(back to editor) and start the level again - *get all actors of a class* indexes are all scrambled.
    Only when I close the unreal engine entirely and load it again does the indexing work properly again, and only once ,like before.
    It is like those actors linger in that level after exit (they should not - did not save any data or anything like that).

    Did anyone had a similar problem with *get all actors of a class* indexing?
    Last edited by Dejan33; 12-08-2019, 02:31 PM.

    #2
    Did anyone had a similar problem with *get all actors of a class* indexing?
    It's a known "feature". Get All does not guarantee element order.

    Comment


      #3
      Thanks for the replay.
      Why does it work the first time?
      I even cleared the arrays and destroyed actors before the loop,and nothing changed - still the same like before.
      Could there be some checkbox in project setting that would solve this issue.

      Comment


        #4
        Like Everynone said, you can't really rely on the indexing order of Get All Actors of Class. The first time, what you noticed in your project, might be the actors being retrieved based on the order in which things were created or stored in memory since you launched the engine. Or there might be some other criteria. Regardless, I believe there is no non-C++ way to change the behavior of the function.

        Also, on a side node. Get All Actors of Class is an expensive function. So if you're going to call it quite often during gameplay, a better option might be store the actors in a separate array at spawn. This way, you also get to make sure that they're sorted based on their assigned indices.
        Last edited by Stormrage256; 12-09-2019, 05:40 AM.
        Unreal Possibilities
        Wave Spawning System | Tower Defense Starter Kit | Floating Damage Texts

        Comment


          #5
          I used get all actors of a class once and promoted the indexed actor to a variable. Worked great.
          Too bad its not consistent.

          Comment

          Working...
          X