Is this a good practice in terms of performace?

I am calling a method in Start() like this: I add all my gameobjects to a List for avoiding using Method Find(“name”) during update.

 for (int j = 0; j < Geos.Count; j++)
            {
                GameObject geometry;
                geometry = GameObject.Find(Geos[j].Name);
                int children = geometry.transform.childCount;
                if (!GameObjectsInScene.Contains(geometry))
                {
                    GameObjectsInScene.Add(geometry);
                }
            }

Then during Update() routine I use :This Find is not for Objects in Unity is for List functions.

GameObject value = GameObjectsInScene.Find(item => item.name == geom.Name);

My application is just exited with code 14 after a while and I do not know if the cause can be this.

Is this a good practice?

Ok… this sounds a bit complex so I don’t understand everything. I am not familiar with this “mirroring scene for another software” your are talking about, so I don’t know what you are doing exactly. Anyway your question seems to be two question : why my program crash ? and how do I improve the code ?

Hope it’s help a little.

------ About the crash ------------

System.OutofMemory. This is a problem with memory allocation. This could be something like an infinite when adding objects in a list if you made a mistake somewhere ?
It’s hard to say just with the info I have.

Anyway, try to comment your code, and check things step by step with Debug.log. See at each step if all is happening as you imagined. You need to find the instruction that cause this.

------ About the improvement ------------

  • Find by name in your GameObjects list, and find by name in a list that contains your object list => It’s the same thing. In both case, you find an object by name in a list. Do you have a way to cut your list into several lists ? A way to “sort” your GameObjects and that would allow you to say “I know which list I want to handle (because of some rule you defined), so I just loop on this specific list and not the others, so I loop on an inferior number of GameObjects”

  • In the same idea, what exactly happens in the Update ? Do you need to send info about all the objects of your system, are just a part of them (that is not clear to me). Send the less info as you can.

  • Can you imagine a way to identify your objects with an numerical id rather than doing a compare on the name ? You could use a list or a Dictionary that allows you to find an object with a known index rather than a compare on the name.

  • In the same idea, imagine a grid of tiles at y=0 were tiles are 1unit squares. I build an array tiles[,] and to get the tile at the position x,z I just do myTile = tiles[x,z] => the identification with array indexes totaly delete a Find on positions, I already know the index I want. Would you be able to find a rule in your system that allows you to identify objects like this ?

  • Are you absolutely sure that you need to send info at each frame, and not just when something happens, like an object that changes it’s position ? Update is called at each frame, so if the instructions you give or not necessary at each frame, use some events instead.