Unity Community


Results 1 to 8 of 8

  1. Posts
    16

    Mesh Render Toggle script?

    Is there a script that will allow me to render meshes off and on when something happens, including turning on meshes in game that are turned off during editing (for cpu sake)


  2. Location
    Leon, Mexico
    Posts
    773
    it depends on your specific use, you may disable the mesh renderer of that gameobject, if you still want that gameobject to be active or if its there some script you wish to remain active, or you can disable the entire gameobject where the mesh is attached
    Cheers!
    Hermes David Montes de Oca Segovia

    XPand Game Level Editor in Asset Store
    create and load levels from external files for unity standalone games


  3. Posts
    16
    Well, basically, I'm going to be building a lot on one scene until i can figure out the spawning between scenes issue I'm having. So i'm wondering if i can disable the mesh (just the mesh) to save on video memory while i'm building on the scene and then when the game is running have a script that reactivates the mesh.

    For example, If I make a door that leads to a cave. Before I go in that door, I'd have the cave unrendered, and when I go in the door, it would re enable the mesh render and possibly disable the above ground mesh render until i left the cave again. All to save on cup usage so the game doesn't crash during creation or play.


  4. Location
    The sunken city of R'lyeh
    Posts
    2,061
    Quote Originally Posted by Calledtogaming
    Well, basically, I'm going to be building a lot on one scene until i can figure out the spawning between scenes issue I'm having. So i'm wondering if i can disable the mesh (just the mesh) to save on video memory while i'm building on the scene and then when the game is running have a script that reactivates the mesh.

    For example, If I make a door that leads to a cave. Before I go in that door, I'd have the cave unrendered, and when I go in the door, it would re enable the mesh render and possibly disable the above ground mesh render until i left the cave again. All to save on cup usage so the game doesn't crash during creation or play.
    Unity does what you're asking for automatically to a certain degree. A mesh that isn't in the view frustum will not be rendered. This would all hinge on your cave model not being one contiguous mesh, but broken up into appropriate pieces. As well as tweaking the far plane of the camera.

    You could also turn objects on or off, based upon triggers as you open the door and progress through the cave. There's much talk about such techniques for performance tweaking in the following video.

    http://unity3d.com/support/resources...e-optimization

    Perhaps the best thing to save you headaches would be to solve the 'spawning between levels' problem you say you have. Have you started a thread on it?


  5. Posts
    16
    Quote Originally Posted by Quietus
    Perhaps the best thing to save you headaches would be to solve the 'spawning between levels' problem you say you have. Have you started a thread on it?
    I have indeed started a thread on it, unfortunately with less than desirable results. I understand the concepts and what's needed in the scenes but it's the application of the scripting that boggles me to a great degree.

    Basically, I need to figure out how to tell the system. "When I load Scene 2, from scene 1, spawn me here. When I load Scene 1 to scene 2, spawn me here, But when i load Scene 1 from scene 3, spawn me here instead". something along those lines.

    It's like when you come out of a dungeon in oblivion, you spawn right outside the door, everything's as you left it outside and inside.

    (i don't know if i'm making sense anymore, But that's essentially my problem. I can't seem to successfully set spawn points between scenes while maintaining all the information that has changed during a scenes activation.)


  6. Posts
    7

    If ur still looking for an answer to this here it is:

    var myMeshRenderer:MeshRenderer;
    //drag the objects MeshRenderer over this variable


    var RenderMesh:boolean = true;
    //this will give you a toggle box on the object
    //containing the mesh



    function Update()
    {

    if(RenderMesh)
    {
    myMeshRenderer.enabled = true;
    }


    if(!RenderMesh)
    {
    myMeshRenderer.enabled = false;
    }

    }
    // also attacheed this
    Attached Files


  7. Posts
    2

    problem

    hi there,

    i am having problems with your script.
    i have a prefab with many objects in it and 1 script for all.
    i would like to disable the meshrenderer for one of the objects (Transform) by script, but it is not working
    "Meshrenderer is not a member of UnityEngine.Transform" i also tried test.myMeshrenderer but it didnt change anything.

    what can i do?


  8. Posts
    11
    Just wrote this little bit of code if anyone stumbles upon this:

    public static void ToggleRenderers (GameObject goCleanUp, bool enabled)
    {
    foreach(Renderer rend in goCleanUp.GetComponentsInChildren<Renderer>())
    {
    rend.enabled = enabled;
    }
    }
    Re-usable method you can use anywhere, disables all renderers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •