- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
Burdock · Sep 28, 2013 at 11:38 PM ·
instantiateoptimizationserializationclasses
Properly reverting to a cashed state
Hey Guys! Im working on a RTS/TBS with some small time mechanics~ Anyway, for playback I need to revert to an earlier state...
But I don't think i'm doing it in an efficient way because whenever I reset, Start
is called before all the Gameobjects are in the right order and initialized~
The symptoms of this are: Things like GameObject.Find
, or GetComponent
often return Missing:
So anyway here is some of the relevant parts of my code:
public void ReplaceAllUnits(int ChildNumber){
//ChildNumber represents the time stamp i want to replace with (IE: 1 would be the first save done, and 2 would come right after)
Transform AllUnits = this.transform.FindChild(ChildNumber.ToString());
//gets the cashed all units
AllUnits.parent = null;
Destroy(GameObject.Find("AllUnits"));
// out with the old AllUnits
AllUnits.name = "AllUnits";
AllUnits.gameObject.SetActive(true);
Debug.Log ("DONE");
}
And how I cash ALL UNITS:
public void CashAllUnits(bool RemoveAll){
string Name = (this.transform.childCount).ToString();
GameObject AllUnits = GameObject.Find("AllUnits");
GameObject NewUnitCopy = Instantiate(AllUnits) as GameObject;
NewUnitCopy.SetActive(false);
NewUnitCopy.transform.parent = this.transform;
NewUnitCopy.name = Name;
}
Comment
Your answer
