Hey guys, I’ve been searching a couple days now, I can’t find a definitive answer on this.
But if I disable the renderer does it not load the object into memory until it’s turned back on?
I know it works with Draw Calls and stuff, but nothing has exactly answered if it’s already preloaded into memory.
(Making a massive online game) that’s why I’m asking.
That way I can optimize as I build so I don’t have to go back to it later.
Thanks in advance guys!
Disabling the renderer of an object merely means that it won’t be drawn. Any scripts attached to the object will continue to run, as will collisions and any physics calculations affecting the object etc. So, yes, it’s very much still in “memory”.
It is loaded in the memory since mesh renderer is one component that is not active but others are like say colllider or rigidbody, which are still taking part in the scene.
And these other components need to perform their job even if mesh renderer is active or not. If the mesh renderer is not active then only the rendering part is not performed but other are.
Here’s a small script to check this thing:
using UnityEngine;
using System.Collections;
public class MeshRendererTest : MonoBehaviour {
// Update is called once per frame
void Update () {
if(transform.position.y <= 1.0f)
{
renderer.enabled = true;
}
}
}
Add this script to any object with a rigidbody set it’s height to anything more than 1, say 10. Also disable the mesh renderer from inspector itself.
Then play the scene, now if the game object is not only loaded in the memory then it will never show up since it will not fall below y position of 1 since it is not present in the memory itself.
But on the contrary the object is visible after it reaches height of 1 because since it has a rigidbody it was falling down due to gravity which means the object was loaded in the memory and was being processed upon.
Also even when the object is deactivated it is still kept in the memory so that it does not need to be loaded when it is activated since loading resources from disc is a heavy job.