cakeslice / Outline-Effect

Outline Image Effect for Unity
MIT License
1.43k stars 198 forks source link

Outlines on scene objects aren't registered if AutoEnableOutlines is false #46

Closed apalade-rkd closed 3 years ago

apalade-rkd commented 4 years ago

If there's an active object in the scene with an enabled Outline, it may not be registered with the OutlineEffect if AutoEnableOutlines is false. The outcome depends on script execution order.

If OnEnable() gets called on Outline first, it will not find an OutlineEffect instance and will not register itself. When OnEnable() is later called on OutlineEffect it also won't register the object because AutoEnableOutlines is false so it completely ignores it.

The fix would be rewriting the OnEnable() in OutlineEffect like this:

private void OnEnable()
{
    Outline[] o = FindObjectsOfType<Outline>();
    if (autoEnableOutlines)
    {
        foreach (Outline oL in o)
        {
            oL.enabled = false;
            oL.enabled = true;
        }
    }
    else 
    {
        foreach (Outline oL in o) 
        {
            if (!outlines.Contains(oL))
                outlines.Add(oL);
        }
    }
}