Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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,104
    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,421
    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,104
    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,421
    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,104
    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,104
    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,421
    @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,104
    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,421
    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,104
    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,421
    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:
    6,237
    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,421
    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:
    6,237
    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,421
    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:
    6,237
    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,421
    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:
    6,237
    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,421
    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:
    446
    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,421
    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:
    446
    - 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,421
    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:
    728
    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,421
    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:
    728
    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,421
    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:
    728
    Cheers Dmitriy! I'll use the padding offset for now!
     
    codestage likes this.
  29. sqallpl

    sqallpl

    Joined:
    Oct 22, 2013
    Posts:
    248
    @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,421
    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:
    248
    Hey @codestage ,

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

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    378
    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,421
    Hey @Shinyclef

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

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    378
    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,421
    Glad it sorted out, thank you for letting me know!
     
    Shinyclef likes this.
  36. developerarreterra

    developerarreterra

    Joined:
    Oct 8, 2018
    Posts:
    8
    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,421
    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.
     
unityunity