Search Unity

Advanced FPS Counter [RELEASED]

Discussion in 'Assets and Asset Store' started by codestage, Feb 12, 2014.

  1. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey, @g0tNoodles !

    Sure, just get the raw data from the counters using documented API and save them to the text document.
     
  2. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    You may see an example in the APITester class in the Examples folder of the plugin, right after the "Raw counters values" label.
     
  3. g0tNoodles

    g0tNoodles

    Joined:
    Nov 28, 2010
    Posts:
    193
    Thanks for getting back to me so quickly.

    How do I access the AFPSCounter variables from my own script? I've tried my regular ways of accessing them but nothing comes up for them. My apologies if I am being dumb...

    Thanks.
     
  4. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Let me shamelessly rip some code from the APITester class:

    Code (CSharp):
    1. GUILayout.Label("  FPS: " + AFPSCounter.Instance.fpsCounter.lastValue +
    2.                 "  [" + AFPSCounter.Instance.fpsCounter.lastMillisecondsValue + " MS]" +
    3.                 "  AVG: " + AFPSCounter.Instance.fpsCounter.lastAverageValue +
    4.                 "\n  MIN: " + AFPSCounter.Instance.fpsCounter.lastMinimumValue +
    5.                 "  MAX: " + AFPSCounter.Instance.fpsCounter.lastMaximumValue +
    6.                 "\n  Level (direct / callback): " + AFPSCounter.Instance.fpsCounter.currentFPSLevel + " / " + currentFPSLevel);
    7.  
    8. if (AFPSCounter.Instance.memoryCounter.PreciseValues)
    9. {
    10.     GUILayout.Label("  Memory (Total, Allocated, Mono):\n  " +
    11.                     AFPSCounter.Instance.memoryCounter.lastTotalValue / (float)MemoryCounterData.MEMORY_DIVIDER + ", " +
    12.                     AFPSCounter.Instance.memoryCounter.lastAllocatedValue / (float)MemoryCounterData.MEMORY_DIVIDER + ", " +
    13.                     AFPSCounter.Instance.memoryCounter.lastMonoValue / (float)MemoryCounterData.MEMORY_DIVIDER);
    14. }
    15. else
    16. {
    17.     GUILayout.Label("  Memory (Total, Allocated, Mono):\n  " +
    18.                     AFPSCounter.Instance.memoryCounter.lastTotalValue + ", " +
    19.                     AFPSCounter.Instance.memoryCounter.lastAllocatedValue + ", " +
    20.                     AFPSCounter.Instance.memoryCounter.lastMonoValue);
    21. }
    22. if (AFPSCounter.Instance.deviceInfoCounter.Enabled) GUILayout.Label(AFPSCounter.Instance.deviceInfoCounter.lastValue);
    23.  
     
  5. g0tNoodles

    g0tNoodles

    Joined:
    Nov 28, 2010
    Posts:
    193
    I saw all of that but how do I access it from another script?
     
  6. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Just access it via Instance:
    AFPSCounter.Instance.fpsCounter.lastValue
    AFPSCounter.Instance.fpsCounter.lastMillisecondsValue
    etc.

    And don't forget to add namespace to the usages:
    using CodeStage.AdvancedFPSCounter;
     
  7. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Of course you need to have AFPSCounter running in your scene in order to access it via Instance.
     
  8. g0tNoodles

    g0tNoodles

    Joined:
    Nov 28, 2010
    Posts:
    193
    I was calling other namespaces - I was going too deep.

    Thanks for putting up with my stupidity.
     
  9. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,422
    @Dmitriy Yukhanov How can I set the Force FPS boolean to true in-game?
    I have tried doing something like this from a developer console but all I keep geting back is that it is unable to set the boolean.

    Advanced FPS Counter.AFPSCounter.ForceFrameRate = true;
     
  10. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey @Labyrith Studios,

    looks like your device OS or hardware doesn't allow this. ForceFrameRate tries to set target frame rate using Application.targetFrameRate with 0 VSync. But it's not guaranteed your app will be able to run at desired FPS.
    Quote from docs:
    "Note that setting targetFrameRate does not guarantee that frame rate. There can be fluctuations due to platform specifics, or the game might not achieve the frame rate because the computer is too slow."

    Please let me know if you meant something else.
     
  11. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,422
    I am running it in the editor, and am trying to set it to -1 (for testing purposes).
    If I set it manually through the editor (even when in play mode) it works and the FPS skyrockets, but if I try to do it in code via my dev console, it fails.
     
  12. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hm... Does the Force FPS checkbox and slider in test scene works for you?
     
  13. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,422
    Yep, that all works fine.
     
  14. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    This means property ForceFrameRate works fine at runtime since all that GUI uses AFPSCounter public APIs, including ForceFrameRate and ForcedFrameRate. Are you sure your dev console works fine with properties?
     
  15. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,422
    with everything else it works fine, never had a problem until now.
    As far as I can tell, the dev console I am using simply runs lines of code in the same way a script would.
     
  16. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    This is even more strange...
    Did you tried to use that API directly from your code? Does it works in that case?
     
  17. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey, guys!

    I'm thinking about switching my plugin from GUIText to the uGUI, as you already might knew.
    I know many of you would like to have both GUITexts and uGUI switchable in the same plugin via some option.
    I'd like to make it so too. But I'm afraid it may lead to the extra garbage and logic complexity in the plugin since I have a lot of code bind to the GUITexts now (labels grouping, etc) which will be not needed for the uGUI at all.

    Thus I have a such idea.

    What if I'll make a whole new asset based on the uGUI and offer it as a FREE upgrade to the existing customers?
    For those of you who has no uGUI I'll keep the legacy GUIText version in the store and will keep making maintenance updates just to make sure it works fine it the latest Unity versions until Unity removes GUITexts at all.

    How do you like this idea? Please, speak out! :)
     
    tosiabunio likes this.
  18. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,422
    I think this is a very good idea.
    I would love to see this as a uGUI component, but I would prefer to keep them separate.

    I think trying to incorporate GUIText and uGUI into a single script is a little cluttered.
     
    codestage likes this.
  19. Korindian

    Korindian

    Joined:
    Jun 25, 2013
    Posts:
    584
    Yeah that works for me!
     
    codestage likes this.
  20. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey, guys!

    I had some additional time to think about new and old versions availability and I've came up to the thought the free upgrade may be a little overshoot to the target goals. Haha, yeah, I'm asking for your feedback once again!

    What if I'll just add the latest current AFPSCounter version with legacy GUITexts as a separate .unitypackage within the actual AFPSCounter package?
    Such way I'll be able to avoid any headache with upgrade maintenance and will keep updating and working on the single package keeping old version inside for the guys with Unity < 4.6.

    What do you think on such plan? :)
     
  21. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    What about using platform-dependent compilation, like:
    Code (csharp):
    1. #if UNITY_4_3 || UNITY_4_5 || USE_LEGACY
    2.     uiModule = new GUITextModule();
    3. #else
    4.     uiModule = new UITextModule()
    5. #endif
    where you've moved the GUI system-specific code into classes GUITextModule for Legacy Unity GUI and UITextModule for the new Unity UI?

    Then you don't have to worry about keeping two versions in sync, and customers don't have to import any extra packages.

    If a 4.6+ customer wants to use legacy Unity GUI, they can define USE_LEGACY.
     
    codestage likes this.
  22. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey, @TonyLi !

    Thanks for your suggestion.
    Something like that was an initial idea, but I decided to abandon it since it might be pretty painful to keep both modules in a same plugin with same "core". The thing is, each UI mode requires specific approach in placement and stacking counters, in whole system initialization and data refreshing. So the significant part of the current code is made with GUITexts in mind (smart updates, stacking data in the single strings linked to the anchors, etc.).
    Also GUITexts feature set is different from the uGUI, so the API consistency may be broken for different ui modules.
    And I'll need to make some extra work to extract GUITexts-specific code to the separate module which is not going to be used by much people. And this work will delay update with uGUI support even further.

    Thus I decided to re-make whole plugin with uGUI output in mind, without looking back to the GUITexts at all, keeping old version in the separate package for the guys on Unity < 4.6...
    Anyway, it's not the final decision, I'm open for a constructive discussion and I hope final decision will suit everyone.
     
  23. tosiabunio

    tosiabunio

    Joined:
    Jun 29, 2010
    Posts:
    115
    My suggestion is to phase out GUIText version. Those who need it would have to live with the module as it now or upgrade to the newest Unity. This isn't crucial extension anyway.
     
    Last edited: Oct 23, 2015
    codestage likes this.
  24. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    codestage likes this.
  25. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    tosiabunio likes this.
  26. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey everyone.
    I'd like to let you know I made few simple tests aimed to check the uGUI performance and got such results:
    - GUITexts are more resources friendly overall
    - uGUI in Unity < 5.2 is not fine optimized
    - uGUI in Unity 5.2 has much better performance and overall resources usage than in 4.6
    - uGUI in Unity 5.2 still uses a bit more memory than GUITexts

    Anyway, I see Unity devs constantly improving performance of the uGUI and it's already pretty nice (in the 5.2), so move from GUITexts to the uGUI shouldn't bring some significant resources usage increase at least on the current Unity versions.

    Have a nice weekend!
     
  27. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey guys!

    Just wish to let you know: moving to uGUI going well, here is an example of output (note, it's not final result):


    First iteration more likely will have same features we had in GUITexts version with similar architecture and logic, but I'll smoothly move to the better architecture with uGUI approach in mind and will add new features requested by customers with future updates.

    Cheers and stay tuned!
     
    tosiabunio likes this.
  28. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Woohoo, Advanced FPS Counter 1.3.0.0 is now live at the store!
    It uses uGUI now instead of legacy GUITexts and has few additional improvements.
    A lot of cool changes onwards, stay tuned!

    Changelog for the 1.3.0.0:
    - legacy GUILayer components replaced with uGUI components
    - new Advanced Settings section with Sorting Order setting
    - new Scale Factor setting at the Look & Feel section
    - GameObject's UI Layer is now default, but not a requirement
    - pixel-perfect positioning for all counters
    - fixed numerous typos in code, strings, docs, tooltips
    - Advanced FPS Counter component placed to the Component > Code Stage menu
    - cleaned Component menu from unnecessary components
    - improvements in editor code
    - numerous changes in API names, refer to updated API docs
    - inspector looks a little bit nicer now
    - code looks a little bit nicer now
    - project updated to the Unity 4.6.1
    - other minor fixes in docs
     
  29. tosiabunio

    tosiabunio

    Joined:
    Jun 29, 2010
    Posts:
    115
    You changed case for at least one file - readme.pdf to Readme.pdf which stupid Unity changed to Readme 1.pdf in order to protect the original file (this "improvement" will be gone in 5.3) during the update. I renamed it back but didn't remember to change the case and ended with small conflict in my SVN. It's a good practice to be case-consistent :)

    Small case changes in the API code as well but those were easy to fix. New version works as before. Good job!
     
  30. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey, @tosiabunio !
    Thanks for your comment, yeah, I'm changing capitalization in all my plugins to match the same rule and I decided to go with first capital letter, to be more consistent with Unity.

    Thus it's a good idea to completely remove previous version before updating to the 1.3 to avoid any naming conflicts, I forgot to mention this at the changelog, sorry ^^

    Anyways, I'm not going to change case in files anymore, so it's a one-time glitch.
     
  31. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    Hello Dmitriy,

    could you please add an option to disable the "<b>[AFPSCounter]:</b> incorrect placement detected! Please, use "GameObject/Create Other/Code Stage/Advanced FPS Counter" menu to fix it!" warning? We're using a custom manager component to enable/disable afps which spawns afps as a child of another GO. It works fine, but the warning is a little annoying.

    p.s. Is there any positive effect (performance wise) marking the gameobject static?
     
  32. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey, @silentneedle !

    Thanks, I'll fix warning to show only when object has non - 0,0,0 position (since it may damage the output).

    Regarding static - it will not be noticeable even if it has any effect for the uGUI I believe. I didn't measured it though.
     
    silentneedle likes this.
  33. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey, guys!

    Just wish to let you know I've submitted for review one tiny update with support of the external canvases.
    So, if you'll place AFPSCounter somewhere inside of the existing Canvas, it will inherit its settings for own nested canvas allowing you to use World Space canvases for the VR projects for example.

    Example:


    Current version is not working with VR because it uses Screen Space Canvas under the hood which is not supported in VR.
     
    Last edited: Dec 8, 2015
  34. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey, update with VR setup support is live now!

    1.3.0.1
    - added support for the external parent canvas (see readme for details)
    - relaxed incorrect placement detection rules
    - minor changes and improvements
    - added new World Space Canvas example prefab
     
    tosiabunio likes this.
  35. OKC

    OKC

    Joined:
    Jan 27, 2014
    Posts:
    8
    Very frustrating to work with if in VR and working in realistic (for physics) scale. I'm working in a 1 unity unit = 1 meter scale so I must scale down the canvas quite a bit which seems to break your VR solution. Why not just send the info to a target text render within the canvas? I'm wasting too much of my time with this...
     
  36. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey, @OKC

    I have no VR solution, I just added support for the parent canvas which can be in World Space render mode supported by VR.

    You may use any settings for your parent canvas (AFPSCounter just creates nested canvas and let it inherit all settings by default).

    Please let me know if you need some additional settings to override in AFPSCounter's canvas and I'll add them for manipulation.

    I can't send info to the target text in canvas, but AFPSCounter has a public API to access all data, so you're free to make a completely custom output for your needs if you're not satisfied with out-of-the-box results.
     
  37. OKC

    OKC

    Joined:
    Jan 27, 2014
    Posts:
    8
    Right, I'm talking about simply scaling down your World Space Example prefab. Stick the prefab under a camera, scale it down and AFPS will begin to render incorrectly, scale it down even more and it will freeze the editor.
     
  38. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    But how are you scaling it down?
    If you're using Canvas Scaler - it won't work by design, it just changes the pixel density in the World Space Canvases according to the docs.

    Not sure how you supposed to correctly scale the World Space canvas content though, looks like the rect transform scale is an only option. But it apparently distorts the entire canvas and its content.

    Also you're free to use few separate canvases - for your scaled ingame UI and for AFPSCounter with appropriate pixel offsets for example..
     
  39. OKC

    OKC

    Joined:
    Jan 27, 2014
    Posts:
    8
    For anyone else with this same issue (until further updates) my programmer came up with a quick fix:

    Open DrawableLabel.cs and add the bolded line:


    internal void CheckAndUpdate()
    {
    if (newText.Length > 0)
    {
    if (uiText == null)
    {
    /* create label game object and configure it */
    labelGameObject = new GameObject(anchor.ToString());

    labelGameObject.layer = container.layer;
    labelGameObject.tag = container.tag;
    labelGameObject.transform.parent = container.transform;
    labelGameObject.transform.localScale = Vector3.one;
     
    Last edited: Dec 11, 2015
  40. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hmm, looks like it works somehow differently in VR environment, since this line does nothing for me and I can't see any changes with or without it when scaling parent canvas through the rect transform in Unity 5.3.

    And localScale doesn't changes for me when I change the scale of the parent Canvas either.

    Could you please share a bit more info on your setup?
    Particularly, what Unity version you're using and what do you see when you have changed scale and have no that line with localScale?

    I'd be glad to add that line and hope the issue will be fixed for everyone, but I'd like to see the issue first and make sure it's a best way to fix it.
     
  41. OKC

    OKC

    Joined:
    Jan 27, 2014
    Posts:
    8
    I can easily recreate the problem in within your example scene:

    Place your World Space Example prefab under the camera, scale down your World Space Example prefab - the object scale/Rect Transform (to say 0.0006), press play.
     
    codestage likes this.
  42. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
  43. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Ah, looks like I managed to repeat it (I' tried to change scale at runtime before, but it breaks when it starts with that scale).

    Huge thanks for pointing me out to the issue, gonna fix it asap!
     
  44. OKC

    OKC

    Joined:
    Jan 27, 2014
    Posts:
    8
    Glad I could help.
     
  45. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    For the others who reads this. You may use fix provided by @OKC or change the line at the file DrawableLabel.cs:
    Code (CSharp):
    1. labelGameObject.transform.parent = container.transform;
    to the
    Code (CSharp):
    1. labelGameObject.transform.SetParent(container.transform, false);
    P.S. just submitted update with this fix for review.
     
    Last edited: Dec 11, 2015
  46. puzzlekings

    puzzlekings

    Joined:
    Sep 6, 2012
    Posts:
    404
    Hi

    I just upgraded my project to Unity 5.3 and while FPS Counter is visible in play mode in the editor, it is now missing from the Android Tablet screen (Experia Z4)

    I was using 1.2.8.2 and then tried it with the latest version and exactly the same thing happens.

    Do you have any ideas why or how to fix it?

    BTW I have to use OpenGL ES 2.1 on the Android tablet - not sure whether this is relevant

    thanks

    Nalin
     
    Last edited: Dec 15, 2015
  47. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey, @puzzlekings !

    I had one another similar report today from a customer who upgraded to the 5.3.
    It seems like a some sort of glitch in Unity when it updates the prefabs \ scenes, but I'm not sure.
    I wasn't able to reproduce it on my side so far (tried to build for my Galaxy Note 3 and it worked fine there).

    However that customer reported the way he fixed this issue: he removed Advanced FPS Counter prefab object from the scene and re-added it through the Menu Game Object > Create Other > Code Stage.

    Another note - he reported prefab worked fine in the new scene, but disappeared on Android from the existing scene (which was updated to Unity 5.3).

    Please let me know if re-adding through menu works for you or not.
    If it will not work, I'd like to ask you for the reproducible case within unitypackage to let me dig into it on my side.
     
  48. puzzlekings

    puzzlekings

    Joined:
    Sep 6, 2012
    Posts:
    404
    Hi @Dmitriy Kovalenko

    hmmm I think I've found the culprit....

    I added like you said after deleting the existing FPS Counter, however it would only show on the device if I tick "Keep Alive", otherwise it will not show.

    HTH

    N
     
  49. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    I'm afraid you've pinged wrong Dmitriy =)

    Anyways, do you add the counter to the initial scene only?
    If you're adding it to the 1st scene and then switch to another you'll need to use Keep Alive for sure to let it migrate from scene to scene. Overwise you need to add it to every scene.
     
  50. puzzlekings

    puzzlekings

    Joined:
    Sep 6, 2012
    Posts:
    404
    Oops - so sorry about that - autocomplete :mad:

    No there is only one scene, which is the point. My feeling is that it may have something to do with the new code for scene loading in 5.3?