Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outline doesn't work on AddComponent #57

Open
Maesla opened this issue Apr 19, 2021 · 2 comments
Open

Outline doesn't work on AddComponent #57

Maesla opened this issue Apr 19, 2021 · 2 comments

Comments

@Maesla
Copy link

Maesla commented Apr 19, 2021

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
Copy link

MattRix commented May 1, 2023

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

@XM-8JD2
Copy link

XM-8JD2 commented Aug 30, 2024

Your method solved my problem, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants