Hello Unityrs…
I tried to compile my project with Unity3d 3, and I was very sceptical …
So, I used a C# script which defined a Class OBJ derifed from GameObject…
now the new compiler tells me that it’s not possible.
I’m asking for some help to understand why.
Kind Regards,
Giancarlo:shock:
It’s Sealed.
You are not supposed to extend classes that are not Monobehaviours or ScriptableObjects.
It was an oversight previously.
The reason is that inheritting gives you access to protected variables, some of which you should not be able to access.
Sorry,
so should it be transformed into a multi inheritance like:
public class OBJ: Monobehavrious :GameObject
ish?
Thanks,
Giancarlo
you can’t extend from internal usage classes any longer. you never should have, extending gameobject for an obj is bullshit, it has no relation to gameobject at all, but Unity 3 made clear you also can’t by just no longer allowing you to do such stuff. This will definitely help quite some project to get its design a bit cleaned from a bloated inheritance mess to reusable, flexible code (which is one of the main reasons for component pattern and the power behind unity - people who want to avoid that shouldn’t have started to use unity at all as they fight the flow at its very base)
Actually it should not even be monobehaviour as it is no behaviour.
All it is is a model asset so you extend it from Object or check out the possible base class on the Assets end (like TextAsset)
If you want to add functionality to a GameObject, add a MonoBehaviour. That is what the MonoBehaviours are for. That is the design structure for Unity.
A GameObject is just a simple container for the Components. It has no special functionality outside of getting components and storing them. It should not have any special functionality outside of that. It’s an organizational object. The functionality objects are the Components, and from a scripting perspective, Monobehaviours. Even the location in the world is a Transform Component, not something inherent to the GameObject.
And yes, if OBJ refers to an OBJ extension mesh, then it is an Asset, and should probably inherit from that structure. Otherwise, after it is imported, and no longer just an asset, it becomes a mesh, which is a generic format and not reliant on specific extensions.
OBJ actually is the extension mesh … I’ll try extending it from the Asset rather then the object.
Than you very much for the help.
Giancarlo