Search code examples
c#inheritanceunity-game-engineunity-networking

Inheritance issue using UNET NetworkBehaviour


I'm having a headache using the State Synchronization support of UNET in Unity3d 5.

According to documentation http://docs.unity3d.com/Manual/UNetStateSync.html The class should inherit from NetworkBehaviour. Well, I'm doing that way:

class Player : Character
abstract class Character : MovingEntity
abstract class MovingEntity : NetworkBehaviour

Where, in Character I'm storing all player data using the [SyncVar] custom attribute. Like this:

public abstract class Character : MovingEntity
{
    [SyncVar]
    public string name;
}

But in inspector I'm receiving the following error:

The type or namespace name `SyncVar' could not be found. Are you missing a using directive or an assembly reference?

and

The type or namespace name `SyncVarAttribute' could not be found. Are you missing a using directive or an assembly reference?

Not a experient programmer in C#. The fact of the class being inherited from another class that inherits from NetworkBehaviour doesn't give me support to do that?

Just FYI, adding [SyncVar] on MovingEntity (That direct inherits from NetworkBehaviour) works just fine.

What I'm doing wrong? There is any good practice in class inheritance that I'm not doing in this example?

Thanks in advance and sorry for the poor english.


Solution

  • You might have forgotten to add the using directive in one of your file:

    using UnityEngine.Networking;
    

    This has nothing to do with inheritance. Each c# file need to explicitly state the namespace it is using. Alternatively, you can use the fully qualified names:

    [UnityEngine.Networking.SyncVar]