Placeholder-Software / WetSurfaceDecals

14 stars 2 forks source link

[bug] New EditorRestartHack component is added every time #27

Closed Janooba closed 3 years ago

Janooba commented 3 years ago

Context

I don't have an exact repro, but WetStuff adds a new EditorRestartHack component every time Startup is called.

Expected Behavior

WetStuff.cs should check for an existing component first before adding a new one.

Actual Behavior

WetStuff.cs adds a new component

Fix

I suggest changing

// Line 59 - WetStuff.cs
#if UNITY_EDITOR
            if (!_appliedEditorRestartHack)
            {
                _appliedEditorRestartHack = true;
                gameObject.AddComponent<EditorRestartHack>().Apply(this);
            }
#endif

to

// Line 59 - WetStuff.cs
#if UNITY_EDITOR
            if (!_appliedEditorRestartHack)
            {
                _appliedEditorRestartHack = true;
                EditorRestartHack hack = gameObject.GetComponent<EditorRestartHack>();

                if (!hack)
                    hack = gameObject.AddComponent<EditorRestartHack>();

                hack.Apply(this);
            }
#endif

Your Environment

Unity 2019.4 WetStuff Version 4.1.0

martindevans commented 3 years ago

That looks like an improvement. We'll probably include it in the next release. Thanks!

As you may have guessed from the name, the EditorRestartHack is a (hacky) workaround for an issue in the Unity editor. The issue may have been fixed now, so we'll also test to see if we can simply remove it.

martindevans commented 3 years ago

Wet Stuff 4.1.2 has just been approved by Unity and is now live on the asset store. That include these changes :)