Saving Enums

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
trothmaster
Posts: 5
Joined: Tue Jan 22, 2013 4:02 am

Saving Enums

Post by trothmaster »

Is the best way to save enums to cast them to an int and then back?
I'm using this:

Code: Select all


public enum LaterousState {
		Default,
		AfterDocking,
		AfterEscape,
		MeetingMercs
	}

public LaterousState CurrentLateroursState = LaterousState.Default;

//Save
ES2.Save((int)CurrentLateroursState,SaveSystemV1.Instance.saveFile + "?tag=" + gameObject.name + "CurrentLaterousState");
//Load
CurrentLateroursState = (LaterousState)ES2.Load<int>(SaveSystemV1.Instance.saveFile + "?tag=" + gameObject.name + "CurrentLaterousState");
Thanks!
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving Enums

Post by Joel »

Hi trothmaster,

That is right, casting enums to and from an int is the best way to save them. You can also cast them to a byte, which is technically faster, though the difference is very, very negligible, especially in the context of a 3D game engine!

All the best,
Joel
Locked