Search Unity

  1. Unity 2018.3 is now released.
    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. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Is it expensive for many IgnoreCollision()?

Discussion in 'Physics' started by Shitman, Apr 15, 2017.

  1. Shitman

    Shitman

    Joined:
    Oct 30, 2015
    Posts:
    227
    I have a tank with collider. Every time it fire a bullet, i set the bullet collider ignore the tank. Of course, the bullet will destroy later, and many many bullets are fired in game.

    My problem is, will all ignorecollision() store in the physics system? After long game run, will it cost performance issue? If so, any way to solve?

    Thanks.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,530
    Just put the tank and the bullets on a different layer then set those layers to not collide. That's the way it should be done. Ignoring collisions between lots of colliders isn't the best way to go.
     
  3. Shitman

    Shitman

    Joined:
    Oct 30, 2015
    Posts:
    227
    Actually, it is a single player rts game, there are many player's units, which bullet may hit any thing in scene, except itself, i.e. player unit A may damage player unit B by mistake.

    If i do it with layer ignore, every tanks need to have its own layer? I may have 20 to 40 tanks in game.
     
  4. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    539
    @MelvMay That is not accurate or feasible as Unity only supports a limited number of layers. Also that normally how its done in. That type of thinking only works with small single player games of a specific type and tech demos.

    As S***man says you can't have every tank on a different layer. Splitting things onto layers isn't feasible for most mid to large size games.

    @MelvMay I'd really like to know if your comment about IgnoreCollision is based on a performance issue with the system. If so that would be a huge disappointment as we waited for months to get this issue fixed and are about to move our system back over from the trigger hack described below.


    @S***man
    I have not profiled ignore collision yet. I had to rip it out previously due to a bug were it was resetting trigger states when used (look up my posts on ignore collision) but this was fixed in 5.5.

    My hack to get around the bug currently has all my projectiles with triggers, so I can early out in code. (they collide with there own hitboxes but know to ignore hit boxes from their owner) Sadly this meant that all my collisions impulses are manual.


    Now that Ignore Collision is fixed we will be moving over to this system, I'll let you know what we find though it may be a few weeks before we have the time.

    I would suggest the following (I have not tried this yet but hopefully the physics system remembers ignores when an object is disabled):
    I would pre-create a bunch of tanks and units on startup. Then disable the gameobjects (pool them).
    Do the same for their projectiles.

    Now assuming you can't pre-pool projectiles for every tank ( maybe you can if each tank only would have one or two shots in flight at a time. If you can then just have the projectiles ignore tank collision on startup.)

    -when a tank is being created I'd "assign it" a set of disabled projectiles and have them ignore its collision. You can space this out over several frames if performance is an issue.

    -Then when shooting the projectiles simple enable them rather then creating them.

    -When they hit disable the projectiles, reset their values and have the tank reuse them.

    Hopefully the projectiles will remember the ignore collision on disable and you wont have to re-create. If they don't remember the collisions I'd open a bug as the system was implemented in a way that wont really fix the issues its meant to fix.
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,530
    I work on the 2D phyics implementation so I know what is feasible or not. In the original post there was no mention of multiple tanks until the reply so please, jumping in telling me what I said was not accurate or feasible is out of order. What I said given the information I was provided and the question being asked is completely accurate and feasible.

    as we waited for months to get this issue fixed
    Can you clarify what you are talking about? Waited months to get what fixed? Is this something to do with 3D physics? There have been no problem with this in 2D physics that I can recall.

    The IgnoreCollision creates a hash from the two Collider2D you specify. That gets put into a hash-table. When two Collider2D are colliding, they get looked up in a hash-table. This is pretty fast but has no outward visibility and is obviously script driven. Doing this when layers do the same job is more than enough. If you need to ignore collisions against multiple items against multiple items (something the original post didn't mention but which you had the knowledge of after the fact) then doing so with layers obviously isn't the best way with the better option being ignoring collisions between colliders. AFAIK, the 3D system works in an identical way too.

    There are new API features coming which will allow much better control of this kind of thing but for now, you're stuck with the API as it is.
     
    Last edited: Apr 16, 2017
  6. Shitman

    Shitman

    Joined:
    Oct 30, 2015
    Posts:
    227
    So, do the colliders in this hash table will be automatically removed if their parent gameobjects are destroyed?

    If not, can i remove specific colliders in this hash table?
     
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,530
    Yes, all the housekeeping is done for you. If either Collider2D is removed then its entry in this table is also removed.

    I mentioned above about features. You may have noticed a new "Info" roll-out in the Collider2D component in the inspector. One of the new features being considered is showing the ignore Collider2D here as well as adding the ability to retrieve/set all Collider2D being ignored. Also the ability to do the same for Rigidbody2D.
     
  8. Shitman

    Shitman

    Joined:
    Oct 30, 2015
    Posts:
    227
    Thanks.

    Can i assume it apply to 3d too? My game is 3d.
     
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,530
    Yes, both 2D & 3D are identical i.e. they both use a hash-table to store the Collider(2D) pairs. You'll get the same results on both in that regard.
     
  10. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    539
    @MelvMay
    Sorry If I came off as attacking you, when you responded to the original post by saying "this is how it should be done" it was upsetting as its often not. I've worked on some large projects, where we had to hack around Unity's implementation of physics to get around issues like those identified by the original poster.




    Long story short. IgnoreCollision would reset trigger states for both the ignored and ignoring and the entire hierarchy. (This functionality was actually in the manual as expected behavior)

    So for example, if a character holding a gun was standing on a pressure plate that opened a door and a bullet was told to ignore a gun in there hand, the gun, and the character holding it would trigger OnTriggerExit and OnTriggerEnter events. The door would play a closing and then opening sound.

    Two threads about the original problem with ignore collision.
    https://forum.unity3d.com/threads/p...tate.340836/?_ga=1.3628534.7558082.1478057180

    https://feedback.unity3d.com/sugges...rigger-state?_ga=1.3628534.7558082.1478057180

    Again sorry to come off as aggressive but your response "this is how it should be done" sent off alarm bells for me that hearkened back to how a feature (that was in the manual as expected behavior) was implemented in a way that did not support medium to large size games.

    Thanks for taking the time to respond.
     
    Last edited: Apr 16, 2017
  11. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,530
    Thanks and it's not a problem. I could see your frustration, I just didn't understand it. We all get there!
     
  12. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,260
    Sorry to chime in, but I don't think this is a proper reply either. Most of us are trying to do games, not just tech demos or single scenes for fun. I think it's easy to figure out that the guy asking the question needs a generic and scalable solution to build a game with tanks, not just a way to to have a single tank firing a single bullet.
     
  13. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    673
    Why would you think it's easy to figure out the op needs a generic and scalable solution to build game with tanks, while all and any information about the game was:

     
  14. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,530
    So you came here to argue and not provide anything useful then, thanks. I'll try to improve my mind reading and extrapolation abilities.

    If I had been given a chance when the user had later written:
    ... then I would've given more appropriate information. As it stands I get criticised for replying exactly to what was being asked and even not replying appropriately to something he asked in the future. Jeez, high horse man.

    You do understand that there's genuine intent to help people here right?
     
    Last edited: Apr 19, 2017
    LaneFox likes this.
  15. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    539
    I think there is a bit of frustration in the community around Unity as a company not having an internal Dev team doing full sized games. The recent release of the Seattle based team has added to that frustration, and seeing how the "unity 5 Adam" video was made increased that frustration even more. (It was incredibly misleading, was barely in engine, and didn't even use lighting that existed in unity 5 at release)

    My alarm bells went off but the current state of affairs isn't really Melve's fault. Unity needs an internal dev team doing full sized games. That way the default thinking inside the company will match the customers. Its super important for the people that make the tools to use the tools the same way the customers do and all that.

    That said I think we need to be careful not to take this frustration out on an individual employee that is trying to help. It will just result in those employees posting less. I should have taken a better tact ,lets be careful not to scare the help we have away. :)
     
    Edy likes this.
  16. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    6,196
    It is not Unity's responsibility to make games, they provide technology and other developers use that technology to create a wide variety of products not limited to games.

    As in the case of this topic's misguided 'frustration', its the same with apparent shortcomings of the technology - users must communicate concerns clearly in order to facilitate corrections by the tech team.
     
  17. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    539
    My philosophy is the best toolmakers always use their tools as the customer does. We will just need to agree to disagree about that one.
     
  18. mkgame

    mkgame

    Joined:
    Feb 24, 2014
    Posts:
    555
    I guess all the problems wouldn't be an issue in this post, if we would have more layers. 32 - 8 = 24 layer for an RTS is a pain. We simply cannot have for each player different layers, so we have to fix it by using ignore collider. In C++ the type can be very long, ( https://stackoverflow.com/questions/5242819/c-128-256-bit-fixed-size-integer-types/5244091 ). A uint1024_t would give us 1024 - 8 = 1016 layers. The CPU can handle it very fast, I don't belive that there would be a big impact in CPU performance.

    The collision matrix UI would be an issue in the state as it is, but anyway, that UI solution doesn't scale.