5
\$\begingroup\$

I am running an experiment in Unity 5 to see the effect increasing the particles of a particle effect has on FPS over time. (this is background work for a much larger piece of work). Currently I write the FPS count from the profiler to a log file and this shows the framenumber and its FPS at that frame. To a seperate log file I write the number of particles on screen and the time.

I have no way of linking these two files to draw up results.

So my question is, how do I write the current framenumber to a file? Can I do this?

UPDATE

I would like the same framenumber that the unity Profiler gives me in its log.

\$\endgroup\$
2
  • \$\begingroup\$ Can you be more specific about what "framenumber" means. I mean, you could simply increment a variable every frame of the game and then write out that number, but I'm assuming that's not the number you're after. \$\endgroup\$
    – jhocking
    Commented Nov 23, 2015 at 12:53
  • \$\begingroup\$ Hey, I would like the same framenumber that the Unity Profiler Log File gives me. Can that be done? This is so as I can link the two log files and create a results graph. \$\endgroup\$
    – CH99
    Commented Nov 23, 2015 at 13:19

2 Answers 2

4
\$\begingroup\$

You can retrieve the number of frames that have passed with Time.frameCount();, if that's what you're looking for.

http://docs.unity3d.com/ScriptReference/Time-frameCount.html

From there, writing to a file in C# is pretty trivial:

http://forum.unity3d.com/threads/how-to-write-a-file.8864/

\$\endgroup\$
2
  • \$\begingroup\$ Thanks! Came across this and figured I had to go with it. The number of frames this claims is off by 1 or 2 in comparison to the count on the top right of the profiler. I say 1 or 2 because its 2 if you pause the game and 1 if you stop running it completely which is weird. So I'll have to be a frame out with my results lol \$\endgroup\$
    – CH99
    Commented Nov 23, 2015 at 14:49
  • 2
    \$\begingroup\$ @CH99 I'm not sure, but that might be related to the fact that your pause and your frameCount() probably don't happen on EXACTLY the same frame. \$\endgroup\$
    – Nzall
    Commented Nov 23, 2015 at 17:00
1
\$\begingroup\$

An alternative to the answer of @KevLoughrey would be:

uint framesSinceStartup;

void Update()
{
    framesSinceStartup++;
}

This is probably the same thing that Unity does for counting frames.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .