- Home /
What is the best way to store a large number of object positions?
My game has many levels. Each level has 50-200 objects in it. I would like to store multiple positions for each object and use iTween to move between them. It would be nice if I didn't have to manually enter the x/y/z for every single object. It would be great if I could store the positions somehow in an array, then move all the objects in the scene view and then store those positions in another array. Does anyone have any suggestions? PlayerPrefs doesn't seem to be a logical place to save such a thing. I looked into Unity Serializer, but it hasn't been updated in a long time. When I added it to my project, there were so many errors that it was unusable.
If you are talking about runtime, then take a look at:
http://wiki.unity3d.com/index.php/ArrayPrefs2
But it sounds to me like you are taking about edit time. You can develop your own editor script. If you are going to be using iTween, you might take a look at the iTween path editor:
http://pixelplacement.com/2010/12/03/visual-editor-for-itween-motion-paths/
Yes, I am talking about edit time. The positions of the objects would need to be saved and distributed with the game itself. Thanks!
Answer by patrik-org · Apr 04, 2014 at 06:44 PM
I'd create the path by placing gameObjects for the waypoints in the path. The waypoint gameObjects would have parameters for the path they belong to and the waypoint order number. Your script then just finds all waypoint gameObjects and creates paths from them. That way you can see your path visually in your scene and can easily alter them if you need to.
This sounds like a good solution, but I'm not sure how it would work in my situation. Consider this. I have 200 objects with rigidbodies and they are all placed in their "home" position. Then the user does some things in the level that move all the objects around and hits a reset button. The reset will iTween.$$anonymous$$oveTo all the objects back to their "home" position. I can surely make a homePosition property on every single object, however, I am dreading typing in x,y,x values for thousands of objects.
I see.. what if you don't have a home-position property but rather as the level starts you loop through all your relevant rigidbodies and store their position in separate lists. You could at regular intervals see if an object has moved and then add their new position to the relevant list - you have your paths ready to be itweened.
Your answer
Follow this Question
Related Questions
Getting any type in Unity Inspector 1 Answer
Saving Object Name in a database when it is clicked ? 0 Answers
Push an object along a path? 2 Answers
Get object/prefab name as string. 1 Answer
SAVE OBJECTS IN ARRAY 1 Answer