dbrizov / NaughtyAttributes

Attribute Extensions for Unity
MIT License
4.53k stars 464 forks source link

[Request] Attributes do not work on MLAPI NetworkBehaviour #254

Open JadenH opened 3 years ago

JadenH commented 3 years ago

From the docs:

NetworkBehaviour is an abstract class that derives from MonoBehaviour and is the base class all your networked scripts should derive from.

Can this package be updated to work on anything that inherits from monobehaviour?

dbrizov commented 3 years ago

UNet is currently deprecated, so I don't plan on making NA to work for NetworkBehaviours. They actually have a custom editor for NetworkBehaviours that is overriding the default NA's editor, that is the reason why it's not working. The developers at Unity are developing a new Multiplayer solution at the moment.

JadenH commented 3 years ago

@dbrizov totally get it if you don't plan on supporting this, however I want to point out that this is MLAPI and not Unet. MLAPI is Unity's new networking solution. It would be cool if this got support!

If I wanted to add support myself, what would I need to do to the custom editor to allow this package to also work?

dbrizov commented 3 years ago

My bad, sorry. I thought UNet and MLAPI are the same things. I am reopening the issue. If there is a custom editor for NetworkBehaviours, and I am most certainly sure there is, then I don't know how I am going to fix this :(

brogan89 commented 3 years ago

Came here with the exact same issue. Also, @dbrizov be prepared the name is going to change to "Netcode for GameObjects" soon 😛based on their Discord server.

image

brogan89 commented 3 years ago

Just had a dive into the code and I see the issue, its because NaughtInspector is using CustomEditorAttribute on every UnityEngine.Object this causes a clash when other custom editors are involved, like NetworkBehaviourEditor in this case. I thought it might've been a simple execution order change but it turns out that's not so easy with editor scripts.

I did find this called Editor.finishedDefaultHeaderGUI however I couldn't work out how to use that to do a second delayed pass on the NaughtyInspector

However, I have a quick and dirty workaround for now so I can get back to working on my game. I just created a new NetworkBehaviour script

    public abstract class NaughtyNetworkBehaviour : NetworkBehaviour
    {
    }

Then made the custom editor script for that but extended NaughtyInpector

    [CustomEditor(typeof(NaughtyNetworkBehaviour), true)]
    public class NaughtyNetworkBehaviourEditor : NaughtyInspector
    {
    }

Then added that new behaviour to my scripts.

    public class Player : NaughtyNetworkBehaviour 
    {

    }

Works like a charm 😉 You can theoretically do this for any other scripts that use custom editors too. A bit cumbersome, but it works.

Would be really cool for NaughtyAttributres to support custom editor scripts, but yeah, I have no idea how to.

BruceKristelijn commented 2 years ago

You can also focus the custom editor immediately to work on all NetworkBehaviours. Doesn't really change a lot but just as a heads-up.

[CustomEditor(typeof(NetworkBehaviour), true)] public class NetworkBehaviourEditor : NaughtyInspector { }

UnityMark commented 7 months ago

Hello, I would like to know about the update for Netcode.