Search Unity

Render() method

Discussion in 'Scripting' started by Deleted User, Aug 30, 2007.

  1. Deleted User

    Deleted User

    Guest

    I had some GL code that I decided to temporarily put in a method named Render() before deciding what to do with it. I didn't see it listed in the script reference class member index, so I figured it's safe to use.

    But when I run the project, this method, in a script attached to an otherwise empty game object, runs and I see the GL drawing. Which is cool - I'd like to keep extra rendering code attached to various objects like this, but is Render a built-in method that I should avoid overriding?


    Code (csharp):
    1.  
    2. function Render() {
    3.     GL.Begin(GL.LINES);
    4.     GL.Color(Color.white);
    5.     for (var edge in edges) {
    6.         GL.Vertex(edge.start_vertex);
    7.         GL.Vertex(edge.end_vertex);
    8.     }
    9.     GL.End();
    10. }
    11.  
    [/code]
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Hm... I don't see any place in Unity where we'd call a Render() method on a script. Are you sure you're not calling that yourself (presumably from some other script)? If you'd put a print("foo") inside the method, you can see the stack trace in unity console.
     
  3. Deleted User

    Deleted User

    Guest

    Good tip - I put in a print("foo") and the console shows it's the first method called in the stack trace. I created a new project from scratch and made a minimal script with just the Render method and a print call, and I attached the script to the main camera, got the same results. I'll send it in via the bug report app.

    ----UnityEngine.Debug:Internal_Log(String, Object)
    ----UnityEngine.Debug:Internal_Log(String, Object)
    ----UnityEngine.Debug:Log(Object)
    ----UnityEngine.MonoBehaviour:print(Object)
    ----NewBehaviourScript:Render() (at Assets/NewBehaviourScript.js:6)
    foo
    UnityEngine.MonoBehaviour:print(Object)
    NewBehaviourScript:Render() (at Assets/NewBehaviourScript.js:6)

    (Filename: Assets/NewBehaviourScript.js Line: 6)


    Code (csharp):
    1.  
    2. function Update () {
    3. }
    4.  
    5. function Render () {
    6.     print("foo");
    7. }
    8.