dbrizov / NaughtyAttributes

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

[Bug] - Overridden methods in derived classes generate multiple buttons #383

Closed SimplicisMirificus closed 7 months ago

SimplicisMirificus commented 7 months ago

Hello! I am unsure if this project is still actively being maintained, but I wanted to post this issue here because I couldn't find anything resembling it during my brief internet searching. If anyone has encountered this or found a workaround for this, I'd be much appreciative to know.

Take the following code for example:

// Base.cs
[NaughtyAttributes.Button("Do Button Clicked")]
protected virtual void Editor_ButtonClicked() => Debug.Log("Clicked Base Class!");

// Derived.cs
protected override void Editor_ButtonClicked() => Debug.Log("Clicked Derived Class!");

Expected results: When placing either the Base or the Derived component on a game object, only one button is shown.

Actual results: When placing the Base component on a game object, only one button is shown. When placing the Derived component on a game object, two buttons are shown.

TylerTemp commented 7 months ago

I think this is a known open issue, though it has a reference said it's fixed.

NaughtyAttributes has many forks and some might have this issue fixed. But as no fork stands-out to replace this upstream version, I have no idea which to choose.

Though I have a separated project which has all the functions of NA and some extra tools. I use it on my own projects & my company's projects.

If you're interested you can have a try. But, using Button (meta attributes) requires an editor level component, which means you WILL need to migrate, and take the potential problems it has

Most APIs are the same as NaughtyAttributes but some still requires some changes.

public class BaseM : MonoBehaviour
{
    [Button("Do Button Clicked")]
    protected virtual void Editor_ButtonClicked() => Debug.Log("Clicked Base Class!");
}

public class Derived : BaseM
{
    protected override void Editor_ButtonClicked() => Debug.Log("Clicked Derived Class!");
}

A 86T(DLR_3VI9LXHWAQ@`H

SimplicisMirificus commented 7 months ago

Ok. I'll give those a look. I'll go ahead and close this issue; since it is a duplicate. Many thanks!