Home Game Development rendering – How to re-render the scene solely when one thing adjustments in Unity?

rendering – How to re-render the scene solely when one thing adjustments in Unity?

0
rendering – How to re-render the scene solely when one thing adjustments in Unity?

[ad_1]

The remark that you simply discovered is correct. Unity was developed as a recreation engine, designed to run video games which are animating on-screen parts repeatedly. In that context, including logic to detect when one thing has modified and re-render solely on demand would really improve value, since you spend additional CPU time doing this validation, when 90%+ of the time the reply is “sure, re-rendering is required”.

Unity is sort of versatile and does provide you with management to render if you need, however since minimizing re-rendering shouldn’t be a core engine characteristic, it could be your duty to trace when you should render and swap rendering on & off.

Here’s a fast proof of idea script that demonstrates this:

public class RenderControl : MonoBehaviour
{
    new public Camera digital camera;

    float _renderFor = 0.1f;
    int _continuousRenderRequests = 0;

    public void RenderFor(float period = float.Epsilon) {
        _renderFor = Mathf.Max(_renderFor, period);
    }

    public void StartRenderingContinuously() {
        _continuousRenderRequests++;
    }

    public void StopRenderingContinuously() {
        _continuousRenderRequests--;
    }
    
    void LateUpdate()
     (_continuousRenderRequests > 0);
        _renderFor = Mathf.Max(0, _renderFor - Time.deltaTime);
    
}

This disables the digital camera from rendering after it is had an opportunity to show the preliminary state of the scene. After this, rendering will be enabled for a set period or till stopped by calling one of many public strategies on this script.

While the digital camera is disabled, no new drawing instructions shall be issued, and no matter you final drew to the display screen stays there. But recreation logic (just like the replace loop that handles consumer enter and checks whether or not it is time to re-enable the digital camera) nonetheless ticks each body.

Note that within the Unity Editor view, you will see a warning overlaid on the sport window “Display 1: No cameras are rendering” to warn you to this, as a result of it is often an indication of an error if it occurs in a recreation. But this warning shouldn’t be current within the constructed executable.

If you employ the UI system, you will wish to set the canvas mode to “Screen Space – Camera” in order that the rendering of the UI is tied to the enabled state of the digital camera. With “Screen Space – Overlay”, the UI will nonetheless render repeatedly over the frozen 3D scene.

You might take this additional by computing the display screen rectangle bounding the modified space, then change the digital camera’s remodel and viewport parameters to restrict rendering to only that rectangle.

However, you will possible discover this extra laborious than it is value. You’ll save the work of rendering your chat window, which is probably going fairly light-weight, however nonetheless be paying the prices of updating all Unity’s different recreation methods – in addition to the obtain value of a full-featured recreation engine. So the effectivity won’t match frameworks which are purpose-built for making this type of cellular app.

Your use case might be higher served through the use of a devoted framework designed for constructing mobile-conscious apps, after which working your minigames both as WebGL apps in an online view, or chaining management to a separate executable for these elements.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here