Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Physics generating unexpected garbage.

Discussion in '2018.1 Beta' started by georgeq, Apr 13, 2018.

  1. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    358
    I would never expect garbage generated from OverlapBoxNonAlloc, the name itself implies it, however It generates 120 bytes of garbage.

    boxna.png

    Another feature that generates garbage but shouldn't is RaycastHit.collider, as you can see below.

    scast.png

    The garbage is generated by a call to FindObjectFromInstanceID. For some reason this last function sometimes, not always generates 40 bytes of garbage.
     
  2. rizu

    rizu

    Joined:
    Oct 8, 2013
    Posts:
    383
    Which Unity version?
     
  3. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    2,519
    Do not profile in the editor. The editor comes with overhead. For example GetComponent calls that don't return any Component, normally allocate a ton of garbage in the editor, which is completely gone in a build. There are various other cases where this is true in the editor.

    Profiling the game running in the editor is quite inaccurate, profile a build on the target hardware instead.

    That being said, I don't remember having seen FindObjectFromInstanceID ever. If that method is new, there is a chance that it's creating garbage memory. However, I still recommend to check that in a build as well.
     
    Last edited: Apr 14, 2018
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    23,024
    Do you have a case number you can drop in the thread so friendly curious staff take a peep?
     
    LeonhardP likes this.
  5. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    912
    Could you please profile the player and see if this allocation occurs there as well?
     
  6. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    901
    A simple GetComponent may generate garbage in editor but not in build (apparently it's because it creates some internal debug string warnings if the component was not found, etc....)

    It's very possible that in this case, OverlapBoxNonAlloc tries to do some GetComponents internally too
     
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,413
    Although I cannot say exactly what it is you're seeing here, know that AFAIK the managed object wrapper (that binds to the native object) is created when you first access any GameObject or Component (any object really). This isn't created each and every time, it's only created once for its lifetime. This may be what you're seeing and shouldn't be a continuous GC penalty.
     
  8. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    358
    2018.1.0b13
     
  9. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    358
    I'm not seeing it every frame, is more like once every second or two, and not at a regular intervals, but certainly more than once.
     
  10. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    358
    No, on the player build I'm not getting any garbage as fas as I could test, so I guess is a false alarm.
     
  11. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    912
    Less severe for sure but not necessarily a false alarm. If you submit a bug report + repro project we can take a closer look at it.