- Home /
Mesh Renderer and Memory
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!
Answer by tanoshimi · Oct 15, 2014 at 12:06 PM
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".
I'm still going to mark this as Correct because I believe you, just wasn't sure.
So okay then, that leads me to another question on the same subject, is there any way to ("Deload") and object and only load it when the player is close enough. No sense in having something there that don't need to be there yet.
@tanoshimi you ninja'd me while I was busy writing a long response to prove it. ;-)
Thanks @tanoshimi and @N1warhead
You can use Instantiate in this case also. You can also use Resources.Load to load resources only when they are required and can Unload them when they are not required.
If possible you can also reuse the same objects like you have enemy A at point #1 then you can teleport the same enemy A to other end of the map say point #2 when player reaches there. In this case you can store the state for that enemy at point #1 so that when player again reaches point #1 you can set this saved state for your enemy A to make him that same enemy at point #1. This is only applicable if it is the same enemy.
If there are two different enemies then loading them at runtime is the option you have.
If I goto enemy, - $$anonymous$$ILL HI$$anonymous$$ lol. - don't really destroy it, just make it move to another end of the map, therefore saving networking overloading lol?
Yes.
I agree.
It's going to be very difficult, but hey if you ever want even a AA quality game you have to put a lot of hard work in to it..
I'm making massive open world environments where you hunt dinosaurs. I'm not talking about like Carnivores game, I'm talking better.
I want to make the Dinosaurs travel in heards, eat other dinosaurs, sleep, fight for leader of their packs, communicate, hear you, get mad, get scared, and so forth. I have experience program$$anonymous$$g Artificial Neural Networks, so I should be able to do it, that is if Unity is like other languages at least.
It's going to get as real as real can get I guess lol...
But there really isn't any story to it, just either single player or online hunting with people around the world lol.
Answer by HarshadK · Oct 15, 2014 at 12:11 PM
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.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Multiple instances of static mesh increase size of game build 1 Answer
Streaming Support 2 Answers
Making a game object un-render or turn-invisible through trigger? 1 Answer
How many objects is too many? 2 Answers