- Home /
Storing Positions of gameobjects
Hi.
What is the best way to store the positions for 1 second of around 50 gameobjects that are moving, and then clean it up after 1 second, and so on. Dictionaries? Can they handle so many entries? I need this for multiplayer lag compensation.
Thanks for help.
Answer by Andres-Fernandez · Apr 09, 2014 at 11:28 AM
If you know the exact amount of positions (50 as you say) and that amount is not going to change, just an array. It's the fastest. C#:
private Vector3[] positions = new Vector3[50];
The problem is that , I have 50 objects and each one of them would need to have their position stored for 1 second, multiple times per second. $$anonymous$$y concern is the performance, I don't know how much entries arrays/dictionaries can take in.
So, you are storing the position of 50 objects many times per second. I think I get it now. That means as many arrays as those multiple times. I don't know then. I would still go for the array because objects could share the same index between different arrays, and you could have a buffer of arrays (many_times_per_second arrays) to avoid the memory mess (lists are pretty cool with memory but heavier on cpu). I believe Lists and dictionaries can handle that many entries, but I think it would be too cpu consu$$anonymous$$g.
Answer by thinkwayne · Apr 09, 2014 at 11:53 AM
Dictionaries can handle any number of entries, they are also very fast at retrieval. Each of your gameobjects should have a unique ID for the key. To keep it tight I would probably just store the transform.Position as Vector3 so you would be storing a assuming you use an int as an ID
Thanks for letting me know, I am storing time and vector3.