Saving custom GameObject in editor mode


I derived a class "Route" from GameObject and it contains some member variables. I then attach a script to it and access the game object by casting it to Route

  void Start()
         Route route = gameObject as Route;

During game mode this turns up as null... Since its derived from GameObject it should automatically get serialized right?

thanks Pranay

What I am guessing is that you have created a script in your project that inherits from GameObject. However the GameObject that you have dragged into the scene is not of that type, but still GameObject and the as operator will therefore not be able to cast this type to Route.

If caching is not possible then what about creating an empty gameobject with all the globally required scripts ?

Or, just create a static class ?

If you need a script to be serializable then you must either inherit from MonoBehaviour or ScriptableObject. And if you require the data to persistent then you must look into creating custom assets.

Why would you want to derive from GameObject? A gameobject is a gameobject and it's capabilities is determined by the components attached. If you need the gameobject to present itself in special ways in the scene or the inspector you can do this with custom Editors that link to your class using `[CustomEditor(typeof(YourClass))]` metadata (and YourClass is derived from `MonoBehaviour` not `GameObject`!) and override methods `OnInspectorGUI` and/or `OnSceneGUI` to display their special things.