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

OceanPlanarReflection does not initialize properly, when oceanrenderer is not present #576

Open
klauskobald opened this issue Jul 7, 2020 · 3 comments · May be fixed by #629
Open

OceanPlanarReflection does not initialize properly, when oceanrenderer is not present #576

klauskobald opened this issue Jul 7, 2020 · 3 comments · May be fixed by #629
Assignees
Labels

Comments

@klauskobald
Copy link

Describe the bug
Problem is, when crest gets instanciated later, not during startup.

To Reproduce
disable oceanrenderer - start - enable oceanrenderer

** Solution **
move some code from Start to OnEnable

Additional context
I am using different ocean systems to be compatible on opengl <3.1 and low end devices.

@huwb
Copy link
Contributor

huwb commented Aug 23, 2020

move some code from Start to OnEnable

Could you please elaborate on this - did you move all the code out of OceanPlanarReflection.Start and into OceanPlanarReflection.OnEnable? I cant get my head around why that would help, but i'm sure theres a good reason!

Would a solution be to remove this code:

            if (OceanRenderer.Instance == null)
            {
                enabled = false;
                return;
            }

So that the OceanPlanarReflections does not shut itself down when theres no ocean?

@klauskobald
Copy link
Author

I cannot say if you solution would work. The problem is, that Start() is only called once. OnEnable() is called whenever it is enabled. So it´s the safe way.

I've put all code in OnEnable() and deleted Start().

       private void OnEnable()
        {
            RenderPipelineManager.beginCameraRendering += BeginCameraRendering;


            if (OceanRenderer.Instance == null)
            {
                enabled = false;
                return;
            }

            _camViewpoint = GetComponent();
            if (!_camViewpoint)
            {
                Debug.LogWarning("Disabling planar reflections as no camera found on gameobject to generate reflection from.", this);
                enabled = false;
                return;
            }
            _camViewpointSkybox = _camViewpoint?.GetComponent();

            // This is anyway called in OnPreRender, but was required here as there was a black reflection
            // for a frame without this earlier setup call.
            CreateWaterObjects(_camViewpoint);

#if UNITY_EDITOR
            if (!OceanRenderer.Instance.OceanMaterial.IsKeywordEnabled("_PLANARREFLECTIONS_ON"))
            {
                Debug.LogWarning("Planar reflections are not enabled on the current ocean material and will not be visible.", this);
            }
#endif
        }

@huwb
Copy link
Contributor

huwb commented Aug 24, 2020

Ok. I'm guessing this still wouldn't work if it's enabled before the ocean, which seems like something we should support, I think

@daleeidd daleeidd linked a pull request Aug 24, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants