Accessing number of drawcalls from script

From Unify Community Wiki
Revision as of 01:34, 6 March 2010 by Gtjuggler (Talk | contribs)

Jump to: navigation, search

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