Accessing number of drawcalls from script

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
 
By: Alex Schwartz (GTJuggler)
 
By: Alex Schwartz (GTJuggler)
  
'''IMPORTANT''' - When running in the editor, scene view cameras will be included in the draw call count!
+
'''Note''' - When running in the editor, scene view cameras will be included in the draw call count!
 +
Also, if you instantiate new objects at runtime, this script will not take those into account, so you should deal with that case manually.
  
 
== Javascript - DrawCalls.js ==
 
== Javascript - DrawCalls.js ==

Revision as of 01:34, 6 March 2010

By: Alex Schwartz (GTJuggler)

Note - When running in the editor, scene view cameras will be included in the draw call count! Also, if you instantiate new objects at runtime, this script will not take those into account, so you should deal with that case manually.

Javascript - DrawCalls.js

<javascript>var drawcalls : int = 0; var allObjects : GameObject[];

function Start(){ allObjects = FindObjectsOfType (GameObject); }

function Update(){ for(var obj : GameObject in allObjects){ var rend : Renderer = obj.GetComponent(Renderer); if(rend && rend.isVisible){ drawcalls++; } }

//print drawcalls Debug.Log(drawcalls);

//reset drawcalls every update drawcalls = 0;

//do some math to find average drawcall count here }</javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox