- Home /
Best data type for many Gameobjects constantly switching?
I have a system where I keep many characters(Gameobjects) in a List. I have several Lists of characters, where the different groups defend different zones of the map. The player can move characters between Lists, and to do that I basically have a For loop adding the desired number of characters to the new List, and then remove those same characters from the old List.
I also have the AI able to do the same thing. I would like to have large groups of characters in the game, and am not sure how costly this would be towards the end game where the players could have several hundreds of characters each. Also, the characters will be switching Lists very frequently, if that changes anything.
Essentially, is a List the best way to achieve this?
Answer by ShadyProductions · Sep 20, 2018 at 07:24 AM
If you're moving 1 character from list its sufficient to use Add,
if you're moving more than 1 you should use AddRange these methods are specifically made to perform better for the ways they were made.
There are several ways you can improve performance with removing items aswel.
Take a look: https://stackoverflow.com/questions/18027575/most-efficient-way-to-remove-multiple-items-from-a-ilistt
I think it will be fine with lists.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How to add and remove objects from a list when they get destroyed and instantiated 0 Answers
How do i go about generating stuff in editor and keeping it in play mode 2 Answers
How to store, change and delete gameobject and it's list element? 0 Answers
Should UI Canvas be used for games similar to 2048? 1 Answer