Search Unity

Advanced FPS Counter [RELEASED]

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

  1. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Longtime fan of this tool, but now getting a bunch of errors when I import it into a project on 2018.3 (not sure if that's relevant). Any suggestions?

    Assets\201 Special Folders CSharp\Plugins\AssetStore Tools\CodeStage\AdvancedFPSCounter\Scripts\AFPSCounter.cs(12,8): error CS0246: The type or namespace name 'Utils' could not be found (are you missing a using directive or an assembly reference?)

    Assets\201 Special Folders CSharp\Plugins\AssetStore Tools\CodeStage\AdvancedFPSCounter\Scripts\CountersData\MemoryCounterData.cs(416,27): error CS0115: 'MemoryCounterData.PerformActivationActions()': no suitable method found to override


    EDIT: We're using Assembly Definition files, but I thought those were only necessary in builds.
     
    Last edited: Jan 23, 2019
  2. codestage

    codestage

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

    Thanks for reporting this issue!

    Looks like you have some issues with Assembly Definitions setup or like so =\
    Could you please share your full setup of the asmdefs in the project
    Also, does it reproduces when you import plugin into the new empty Unity 2018.3 project?
     
  3. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Well, we have a lot of asmdef files in the project, in each Editor folder. What exactly do you want to know?

    I suspect we can fix the first type of error with asmdef, but what about the other one?
     
  4. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Thanks for the quick reply.

    Looks like Runtime\Scripts\AFPSCounter.cs is placed into the asmdef separately from Runtime\Scripts\Utils folder or its asmdef has no proper reference to the assembly where Utils is placed at.

    I'd suggest such asmdef setup for AFPSCounter:
    Plugins\CodeStage\AdvancedFPSCounter\Runtime\AFPSCounter.Runtime.asmdef
    Plugins\CodeStage\AdvancedFPSCounter\Editor\AFPSCounter.Editor.asmdef, compiling for editor platform only and with a reference to the AFPSCounter.Runtime

    Looks like second error has the same nature and hopefully proper asmdef setup will fix it too.

    For now, I can't reproduce these errors in the new empty Unity 2018.3.2.
    Could you please let me know if it reproduces for you in an empty project anyway?

    Thanks!
     
  5. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    ok, thanks, we'll do that and see. (If those don't work, then I'll try importing into an empty project.)
     
  6. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Adding asmdef files fixed all those errors, so sorry for the false alarm (I'd just not seen errors in the editor, only in builds).

    So new question: The memory usage readout is very helpful, but I don't understand why that readout is generally significantly smaller than what Task Manager shows. (e.g. in my title scene, AFPS shows about 1 GB while Task Manager shows 2GB). Any insight on that?

    thanks
    Dave
     
    codestage likes this.
  7. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    @gecko Thanks for trying new asmdef settings, glad to hear you have those errors gone!

    AFPS gets those readouts from the Unity runtime as is.
    There are 3 different RAM readouts - are you talking about total one?
    If yes - it should return (quote from Unity docs) "total memory Unity has reserved for current and future allocations. If the reserved memory is fully used, Unity will allocate more memory from the system as required."

    Please note, task manager can show both working set and private bytes readouts and they can differ significantly depending on your hardware configuration, runtime lifecycle and operating system:

    upload_2019-1-28_0-56-39.png
     
    gecko likes this.
  8. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Checking again, actually, in the title scene the numbers are very similar. But in my game scene, AFPS has two MEM readouts, Total and Alloc -- Total is 2708mb and Alloc is 2186. Task Manager for me (Win10) has just one Memory column, which says 4161mb. I don't see any Private/Working columns.

    So any idea why those are different? There's 1400mb of unaccounted for memory according to Task Manager....which is significant if I want this to run on computers with 4GB of RAM! :/
     
  9. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    It could be something specific to how Unity Player calculates own reserved memory, worth asking QA about this.
    Going to ask them, but I need some more input to construct proper query.

    What is your exact Unity version?
    Are you checking memory in running build or in editor's Play Mode?
    If you check mem in build - is it a dev or release build?

    Thanks!
     
  10. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    What is your exact Unity version?
    2018.3.2

    Are you checking memory in running build or in editor's Play Mode?
    Build -- release, not dev

    thanks!
     
    codestage likes this.
  11. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey everyone, glad to let you know AFPSCounter 1.4.0 is live at the store!

    This release brings fixes, improvements, built-in assembly definitions and update to Unity 2017.4.

    - remove ContentSizeFitter and HorizontalLayoutGroup when not used
    - improve Average FPS calculation performance
    - update project to Unity 2017.4
    - add Assembly Definition files
    - remove some legacy code
     
  12. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,408
    Hi,

    Is it possible to make this visible in LWRP (universal renderer)?

    (although as a work around, i guess can use the API to query fps value, just need it once basically)
     
  13. codestage

    codestage

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

    Thank you for reporting this problem.

    It should work just fine at the LWRP though. Just tried it at 2019.2.0 LWRP template:

    upload_2019-7-30_23-34-43.png

    Could you please let me know your Unity version and steps to reproduce the problem?
     
  14. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,408
    2019.3.10a + android + lwrp from unity github (latest master), didnt seem to get that ui visible in device..

    but no problem, could be alpha version issue?
    i used the api to get that value, so thats fine for now.
     
  15. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Thanks, this seems to be a Unity Alpha bug.

    I just tried it with 19.3.10a at the PC build and it runs just fine. So it have to work similarly at all other platforms. If it does not - it's a Unity bug.

    Could you please let me know what's your target platform?

    I could try reproduce it and send a bug report to Unity.
     
  16. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,408
    tested in empty scene (dropped fps prefab in, enabled autoscale)

    pink boxes, without lwrp enabled in graphics settings (to android 9.0 device)
    no errors or warnings in logcat.
    screen2.png *device screenshot


    with lwrp enabled, empty screen
    screen2.png *device screenshot


    in editor (pc) both works fine.
     
  17. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey, this is weird =\

    I did tested it at Unity 2019.3.10a on Android (Galaxy S7) and it works fine there (just added counter to the existing sample scene):
    Screenshot_20190731-123845_werwerwer.jpg

    Did you tried to test it on another device or in fresh new 2019.3 project?

    Anyways, I'd suggest to submit a bug report to Unity and wait for 2019.3 to out into release since it's alpha and can have a lot of bugs.
     
  18. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,408
    tested on android 8.1 device, same problem.

    i'm thinking the issue actually comes from using the latest github lwrp, instead of the package manager one.
    i think can consider this solved, since it works fine on that your lwrp scene.
     
    codestage likes this.
  19. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Thanks for the additional info, @mgear

    Please let me know if you'll have this problem unsolved to the 19.3 release date.
     
  20. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    I understand that the "force FPS" feature is not guaranteed to work. It doesn't work in my scene. Is there any way to troubleshoot that or is it due to some Unity limitation?
     
  21. codestage

    codestage

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

    It may not work due to the hardware limitations and such, here is a quote from the docs:
    Could you please share a bit more info on your case?
    - what is your Unity version?
    - what is your target platform?
    - does it works in Editor?
    - what is your VSync value in the Quality settings?

    Thanks!
     
  22. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    - what is your Unity version? 2019.2
    - what is your target platform? Windows
    - does it works in Editor? no
    - what is your VSync value in the Quality settings? Every V blank

    I did some more testing and it seems that the "force FPS" feature does what it's supposed to do. The scene uses rigid body physics. I wanted to view it in slow motion (fps=1). Unity (Editor Statistics and AFPS) actually shows fps around 1, but the physics engine is probably doing its own thing :) In any event, it's not an AFPS issue. Sorry for the confusion and thanks again for a great asset.
     
    codestage likes this.
  23. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Thanks for providing all the info.

    If you set Force FPS to 1 and see actual FPS equal to 1 then Force FPS feature works correctly.

    Please try using the Time settings and set timeScale to the lower value here:
    upload_2019-9-4_16-35-0.png
     
    username132323232 likes this.
  24. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Hi there. I just updated to the latest version of AFPS (in Unity 2019.3b10) and now the counter is systematically off-screen.

    In this example it's at the top right corner:



    But it's the same issue for every corner. It looks like either the offset value is wrong (it's -5f, it should be -60f for the top right corner) or the anchor point of the counter is not set to the proper corner. Could you please take a look at this? Cheers...

    Update:
    So far my temp way to fix it (although it's damn ugly) is to do this in an update:

    Code (csharp):
    1. afpsCounterTransform.Find("CountersCanvas/UpperRight").GetComponent<RectTransform>().anchoredPosition = new Vector3(-60f, -60f, 0);
     
    Last edited: Nov 10, 2019
  25. codestage

    codestage

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

    Thank you for reporting this problem!

    Would be great to know a bit more about your case:

    - Could you please confirm it does reproduces for you at the ExampleScene?
    - Also could you please check you have proper padding offset values set in the Look & Feel settings (it's 5, 5 by default)?
    - Does it reproduces for any target platforms of only for specific ones?
    - Is it possible some specific settings lead to this misbehavior?

    Unfortunately I could not reproduce it at Unity 2019.3.0b10:

    upload_2019-11-10_20-37-3.png


    I'll be glad to take a look at the repro case or to see what settings you're using and how you're starting it (from code, or added in scene).

    Thanks!
     
  26. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Hi Dmitriy. Thanks for your quick reply!

    So after more digging it turns out the issue stems from the fact that the UpperRight panel's Width and Height are set to 0 by default (which they probably shouldn't). So that's why the behaviour is not the expected one.



    For example with padding offset values of 5 and 5 the counter frame should fit neatly in any corner. But since the width and height are set to 0, the panel behaves as though its pivot is in its center (hence it is mostly pushed off-screen).

    So as a fix I would simply suggest to give the UpperRight panel (or all of them actually) a default size of 150 x 50. I hope you see what I mean. Please let me know if that's not clear...
     
  27. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Thank you for a quick come back with more details!
    I managed to reproduce this problem, and will fix it with next update.

    As a workaround, please enable background effect at the Look & Feel settings (and feel free to use transparent color if you do not need an actual background).
    Or you can use Padding Offset at the Look & Feel settings (e.g. set it to 60, 60).

    Thank you for detailed bug report, it helps a lot!
     
    Last edited: Nov 10, 2019
    Seith likes this.
  28. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Cheers Dmitriy! I'll use the padding offset for now!
     
    codestage likes this.
  29. sqallpl

    sqallpl

    Joined:
    Oct 22, 2013
    Posts:
    384
    @codestage

    Hi,

    I'm using 1.3.3.1 version and I know that I should update it but I have a question.

    I've upgraded Unity from 2019.1 to 2019.3 and everything worked fine with AFPSC. I wasn't using it for few days and now I'm getting this error when trying to access it.

    The weird thing is that I'm getting this error on all projects, even fresh ones.

    It's important for me because if it worked before and now it spams this error in all projects so I'm wondering if it could be related to editor.

    Any help will be much appreciated.

    Thanks.

    EDIT: Found it. It won't work if the scene reload is disabled in the new 'Enter Play Mode' settings.
    It works when it's enabled but it's impossible to access the inspector GUI and the error is logged when I'm trying to access it.

    It's possible that I've missed this error after upgrading to 2019.3 because the plugin was working in the game view so I just wasn't touching the prefab and component in editor. Some time after disabling 'scene reload' I've noticed that plugin doesn't work in the game view and then I've checked prefab and script for the first time since upgrading to 2019.3.

    If it's just an incompatibility between 1.3.3.1 and 2019.3 please let me know.

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. CodeStage.AdvancedFPSCounter.Editor.UI.EditorUIUtils.Separator (System.Int32 padding) (at Assets/Plugins/CodeStage/AdvancedFPSCounter/Scripts/Editor/EditorUIUtils.cs:34)
    3. CodeStage.AdvancedFPSCounter.Editor.UI.EditorUIUtils.Foldout (UnityEditor.SerializedProperty foldout, System.String caption) (at Assets/Plugins/CodeStage/AdvancedFPSCounter/Scripts/Editor/EditorUIUtils.cs:62)
    4. CodeStage.AdvancedFPSCounter.AFPSCounterEditor.OnInspectorGUI () (at Assets/Plugins/CodeStage/AdvancedFPSCounter/Scripts/Editor/AFPSCounterEditor.cs:247)
    5. UnityEditor.UIElements.InspectorElement+<>c__DisplayClass58_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <ffcf2f9855fe46038192299154f37a45>:0)
    6. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
     
    Last edited: May 23, 2020
  30. codestage

    codestage

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

    Thank your for reporting this problem.
    It is caused by API changes introduced in Unity 2019.3. It was fixed in AFPSCounter 1.4.1.

    Feel free to update plugin to work with newer Unity versions!
     
  31. sqallpl

    sqallpl

    Joined:
    Oct 22, 2013
    Posts:
    384
    Hey @codestage ,

    Good to know. I will update it. Thanks for your reply!
     
  32. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    I'm using the 2020.2.0a12 alpha.
    It is reporting that the latest version is 1.3.4.0.
    I'm unsure why, I've tried removing the package and hitting 'update' again, which lands me back on this version.
    Any idea how I can get the latest for fixes for the API changes?
    upload_2020-6-13_21-6-38.png
     
  33. codestage

    codestage

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

    Did you tried using release Unity version to download AFPSCounter?
     
  34. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    505
    Ok that was weird but I have it fixed.

    I tried from a new project but that didn't work either so I figured some weird caching situation going on.
    Deleting the code stage folder in the package cache didn't work. However, I deleted everything in the cache and that did work. So there was something that I missed in the cache. Now it is working.

    Cheers.
     
    codestage likes this.
  35. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Glad it sorted out, thank you for letting me know!
     
    Shinyclef likes this.
  36. developerarreterra

    developerarreterra

    Joined:
    Oct 8, 2018
    Posts:
    17
    Zo we just bought your plugin after a couple of our own attempts at getting the used memory on an Android device.
    But we get the same result as our own code. Which is way to low to be correct.
    One screenshot is from our empty scene, with no content loaded. The other with a lot of content loaded into the scene. We download these from a server and then load them (Asset Bundles, OBJ, Textures, all kinds of assets). We're using 4k textures for testing.

    Empty: 51.59MB
    4K Textures: 50.92MB
    AssetBundles: 65.82MB

    In The Unity editor
    Empty: 1.03GB
    AssetBundles: 1.39GB
    Textures from empty 209MB go up to 0.90GB in the Assetbundles scene
    Meshes from empty 7.3MB go up to 136MB in the Assetbundles scene

    using Unity 2019.2.21f1
     

    Attached Files:

    Last edited: Sep 16, 2020
  37. codestage

    codestage

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

    I'm sorry for a late reply, somehow missed email with the notification.

    AFPSCounter does internally rely on the Unity's APIs which do provide memory usage information:
    Profiler.GetTotalReservedMemoryLong / Profiler.GetTotalAllocatedMemoryLong

    Please feel free to try reporting this to the UT in case you see some abnormal memory usage values AFPSCounter reports.
     
  38. Gleb_Palchin

    Gleb_Palchin

    Joined:
    Jan 7, 2016
    Posts:
    22
    Hey @codestage,
    Is your asset using an assembly definition so it is not wasting time and don't get compiled everytime when I change my code?
     
  39. codestage

    codestage

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

    Yes, I'm using asmdefs in all of my assets ^^
     
    Gleb_Palchin likes this.
  40. Gleb_Palchin

    Gleb_Palchin

    Joined:
    Jan 7, 2016
    Posts:
    22
    Thanks!

    Other question is if you are planning to use TextMeshPro or at least have 2 variants for native Text or TextMeshPro usage?

    This is just for optimization reasons for mobile devices so it will have minimal impact on performance when testing the games.
     
  41. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Yes this is planned, for now you can use AFPSCounter in background mode (to get all values from APIs) and draw it using your own UI (either on TMPro or UI Toolkit for example).
     
    Gleb_Palchin likes this.
  42. Gleb_Palchin

    Gleb_Palchin

    Joined:
    Jan 7, 2016
    Posts:
    22
    And the last thing is the gesture option which is bad for mobile devices, for any game where the joystick is used for the movement of the character the counters we will be triggered on and off if will move the character in circles.

    Any plans to introduce new gestures or hidden buttons? Or we will have to make our own gestures?
     
  43. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    @Gleb_Palchin currently there are no plans on adding more gestures since it's hard to make universal activation triggers which will suit most customers.

    Feel free to switch AFPSCounter using its APIs from your own buttons, gestures or any other suitable triggers instead of built-in gesture and hotkey.
     
  44. Gleb_Palchin

    Gleb_Palchin

    Joined:
    Jan 7, 2016
    Posts:
    22
    Ok, thanks for anwsers, I switched our projects from SRDebugger to this one, hope it will serve well, waiting for more cool features and updates!

    Also using Maintainer, great asset aswell!
     
    codestage likes this.
  45. Gleb_Palchin

    Gleb_Palchin

    Joined:
    Jan 7, 2016
    Posts:
    22
    @codestage
    Is there any setting to fix the issue with the Average FPS calculations?
    More details:

    1. Start the game with FPS Counter disabled
    2. Enable it during the game (while the game is an empty scene with stable 60fps)
    3. Look at the Average as it goes from 0 to 59fps during a minute or so.

    Expected behaviour is that the average should be at 59-60 from the start.

    I assume that the problem is that the first frame rate value is 0 in your samples which is taken in account don't know why(, and when dividing to the number of samples it shows wrong number which increase slooowly to the actual correct number.
     
  46. codestage

    codestage

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

    Thank you for reporting this problem, adding this to the internal task tracker for the investigation and fix, for now you can reset it manually by calling
    Code (CSharp):
    1. AFPSCounter.Instance.fpsCounter.ResetAverage();
    right after you activate counter.
     
  47. Gleb_Palchin

    Gleb_Palchin

    Joined:
    Jan 7, 2016
    Posts:
    22
    I made it right after activation

    Code (CSharp):
    1.  
    2.             AFPSCounter.Instance.OperationMode = OperationMode.Normal;
    3.             AFPSCounter.Instance.fpsCounter.ResetAverage();
    And it doesn't work, the problem is in the value update method, right on the first frame when the average is calculated for the first time.
     
  48. Gleb_Palchin

    Gleb_Palchin

    Joined:
    Jan 7, 2016
    Posts:
    22
    Actually Reset Button in the Editor(Inspector) helps, it works, I will take a look at what method is called and do the same
     
  49. Gleb_Palchin

    Gleb_Palchin

    Joined:
    Jan 7, 2016
    Posts:
    22
    So the reset helps only if it was made with a delay

    Code (CSharp):
    1.  
    2.  
    3.         private void SwitchCounter()
    4.         {
    5.             if (operationMode == OperationMode.Disabled)
    6.             {
    7.                 OperationMode = OperationMode.Normal;
    8.  
    9.                 StartCoroutine(ResetCoroutine());
    10.             }
    11.             else if (operationMode == OperationMode.Normal)
    12.             {
    13.                 OperationMode = OperationMode.Disabled;
    14.             }
    15.         }
    16.  
    17.         private IEnumerator ResetCoroutine()
    18.         {
    19.             yield return new WaitForSeconds(1f);
    20.  
    21.             fpsCounter.ResetAverage();
    22.         }
    This change helped to have a correct average from the first time.

    P.S. This issue is present only when the counter is activated for the first time, everytime we activate it again the average is working good even without this "reset" workaround.
     
  50. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    @Gleb_Palchin thank you for all the details, it will help to eliminate this defect faster.