Hi developers! I've been creating my own 2D Waypoints system (predominantly for iOS/Android). Now each waypoint's game object destroys in Awake() (to free memory). But I thought: "what if I could save their positions in the file inside of Unity Editor and then just load them from a file in game?" So my question is: what's faster to do in Awake() for 500 waypoints (game objects)? 1. Get their position and then destroy objects (as I'm doing now). 2. Load 1500 lines of text with their position from file. I have 'Waypoint.cs' script: Code (csharp): using UnityEngine; public class Waypoint { public Vector3[] Points; public Waypoint (Transform PointsParent) { Points = new Vector3[PointsParent.GetChildCount()]; for(int i=0; i<PointsParent.GetChildCount(); i++) Points[i] = PointsParent.GetChild(i).position; } } And 'Waypoints.cs', which loads all waypoints and destroys PointsParent (from 'Waypoint.cs'). Sorry for my bad English. Thanks!
Time wise? You're doing this at load time? I don't know which would be faster. Depends on the size. Why don't you do a unit test and see. Just time how long each takes, do it several times over different conditions (different number of waypoints, different devices), and see which wins. Personally I would go with a file, not because it's faster but for organization.
Use a file. It would just contain the information you need, could be read by other applications (i.e. external enemy movement editor) and is certainly more easy to swallow for the garbage collector. And I am 99% sure that it would be faster.
If he's loading them in from disk, he will storing them in memory during gameplay. To the OP: Given that you're doing this once when the game starts, there are about a billion other features you could add or optimizations you could make before this becomes an issue - just use the easiest or prettiest method and move on. I personally would use andeeeee's suggestion and store them all in an array of Vector3s, and write a custom editor script to make it easy to place them. It's easier than a text file and removes the overhead of having 500 gameobjects in your scene.
But it's not what they're asking about... ::facepalm:: Just because a car needs gasoline doesn't mean "you should get gasoline" is a good answer to the question "what's a good interest rate for a car?"
Okay, so he was only talking about speed. That doesn't mean he should be ignoring the memory footprint of his method, and flaminghairball was doing him a favor by mentioning it.