cakeslice / Outline-Effect

Outline Image Effect for Unity
MIT License
1.5k stars 201 forks source link

Outline doesn't work on AddComponent #57

Open Maesla opened 3 years ago

Maesla commented 3 years ago

If you add outline after start, it doesn't work.

Steps

  1. Setup the camera with Outline Effect
  2. Add a cube to the scene
  3. Press play
  4. Add Outline component to the cube
  5. Verify that the outline is not visible

Cause

IsVisible = false although actually is visible. OnBecameVisible event is the event used to change the value of that flag. Because this event was already triggered, when you add the Outline component, the value visible doesn't change because the event was fired before

Fix

Possibly, do some checks at OnEnable and decide if this object is visible or not

Workarround

Forcing the mesh to disable/enable triggers again OnBecameVisible event

            public void AddOutline(GameObject go)
            {
                var outline = go.AddComponent<Outline>();
                bool isRendererEnabled = outline.Renderer.enabled;
                if (isRendererEnabled)
                {
                    outline.Renderer.enabled = false;
                    outline.Renderer.enabled = true;
                }
            }
MattRix commented 1 year ago

Thank you for this workaround, it worked great for me!

XM-8JD2 commented 3 months ago

Your method solved my problem, thank you