Alternative Restorestate method?

I took the mini-challenge and wrote my own RestoreState before Sam, and found out as the lesson went on that what I wrote was different than what the course teaches.

I’m of course rewriting to match the taught script, but for learning purposes I’d like to ask if what I came up with is total gibberish, or if it has any bug or shortcoming compared to the one in the video.

Dictionary<string, object> stateDictionary = (Dictionary<string, object>)state;

foreach (KeyValuePair<string, object> entry in stateDictionary)
 {
       ISavable component = (ISavable)GetComponent(entry.Key);
       if (component != null)
       {
              component.RestoreState(entry.Value);
       }
}

I went ahead and plugged this into my own project, and it worked.

I don’t see any specific problem along the way.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms