Mesh Render Toggle script?

Discussion in 'Scripting' started by Calledtogaming, Mar 8, 2010.

  1. Calledtogaming

    Calledtogaming

    New Member

    Joined:
    Mar 2, 2010
    Messages:
    16
    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. CoatlGames

    CoatlGames

    New Member

    Joined:
    Apr 25, 2008
    Messages:
    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
     
  3. Calledtogaming

    Calledtogaming

    New Member

    Joined:
    Mar 2, 2010
    Messages:
    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. Quietus2

    Quietus2

    Member

    Joined:
    Mar 28, 2008
    Messages:
    2,061
    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/unite-presentations/performance-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. Calledtogaming

    Calledtogaming

    New Member

    Joined:
    Mar 2, 2010
    Messages:
    16
    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. xortrox

    xortrox

    Member

    Joined:
    Feb 13, 2011
    Messages:
    7
    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. veganophob

    veganophob

    New Member

    Joined:
    Apr 15, 2012
    Messages:
    2
    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. Kastar Troy

    Kastar Troy

    Member

    Joined:
    Jul 18, 2012
    Messages:
    13
    Just wrote this little bit of code if anyone stumbles upon this:

    Re-usable method you can use anywhere, disables all renderers.