|
Hello, 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? thanks Pranay
(comments are locked)
|
|
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.
(comments are locked)
|
|
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 I have generic data that all my game objects need. For example the event manager. I have a simple event system that i use instead of SendMessage (due to performance issues) now if i need to send an event to a game object i have to get the EventManager Component through GetComponent<> this again is bad for performance. I have looked into the option of caching but in my case its not an option. so to avoid these things i would like the put the event manager in the gameobject using the above method.
Jan 11 '10 at 02:40 PM
pkamat
(comments are locked)
|

Reading what you intend to do with this. I'm looking forward to a working solution, too.