I am working on a project which empiles a database. For now I am loading the data from a .CSV file which contains about 23k rows, each row equals 1 item.
The prefab I use for this purpose is a cube with a script attached to it with some string variables like id, name, description and quantity, this to set and get properties of the objects, so I can manipulate it.
What I need to do is, by clicking a button I need to Instantiate the prefab, then assig all the corresponding strings from the .csv to the prefab string variables, and finally add all the GameObjects to a List.
In a few words I need to create a cube for each object in the database and then, position it and render it on screen.
I already did that, but the fact that there are about 23k objects, Unity freezes, so I was tinking about a separate thread and found this video:
But I can not use “someGameObject.GetComponent ().SomeMethod();” from a thread which is not the main thread.
So I wonder if there is a better way to Instantiate prefabs, setting propoerties and then adding toa list?
I would avoid making them live objects and instead manage them from a single script that holds the data of each one, instead of needing to GetComponent on instantiated objects. You could then also use direct GPU instancing to pump up the efficiency drastically as well.
Thank you for your response, I think I will create a list of a group of objects, then add that list to an other list, so I won’t have to loop trough every 23000 objects per frame, instead I will only loop trough thosee from a specific list.
My idea wasn’t to make any actual objects. Just instantiate a list of the CLASSES that hold values, and render your cubes using GPU instancing, don’t instantiate new cubes.