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
During game mode this turns up as null... Since its derived from GameObject it should automatically get serialized right?
asked Jan 11, 2010 at 12:58 PM
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.
answered Feb 08, 2010 at 06:54 PM
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
answered Jan 11, 2010 at 01:41 PM