Suppose I want to record all the public variables of a GameObject to a text file. What’s the best way to do that? I’m thinking an iterator that runs through all the public variables, but how do I get a list of the variables and check if they’re public or not?
in my opinion it would be the easiest to have all publics in one script or put a reference to them in an array. i don’t know if it’s possible to check if they are public.
The variables are different data types though. Is there a data non-specific array?
You should be able to accomplish this using reflection. (A search for ‘reflection’ here or on Unity Answers should turn up some examples, but post back if you need more info.)
Just out of curiosity, what do you need to do this for?
Thanks for the tip, Jesse! We’ve run into some problems transferring scene files from one build to another. We’re using Indie so there’s no external version control. What’ve found is that sometimes the links between prefabs or scripts get broken. We’ve had entire levels be stripped of the set pieces, and all the settings for the level (enemies spawning and stuff) be returned to their default script values.
Basically, the idea is, when we’re transferring a scene to someone else’s build, save the settings to an external file, then reload them if something goes wrong.