Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

memory problem

Discussion in 'Getting Started' started by littlewombat, Feb 11, 2015.

  1. littlewombat

    littlewombat

    Joined:
    Feb 11, 2015
    Posts:
    13
    Hello, I don't know which functions needs more memory, is it ontriggerenter+ontriggerexit or ontriggerstay? I need to check if player is in collider but in first way with triggerenter+triggerexit first have to transform object with collider for example (0,-100,0) because if player is on collider and object with colider is destroyed function ontriggerexit doesn't work. So first solution is more complicated because there are a lot of colliders but in my opinion ontriggerstay need a lot of memory and me worried about any lags. What is your opition? Should I use triggerenter+tiggerexit or triggerstay?
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    None of these methods in and of themselves should use that much memory. Most games are not memory constrained anyway (though memory access is slow these days for hot code).

    The biggest constraint will be processing speed. OnTriggerStay will chew through CPU cycles. In general its better to use Enter+Exit. You can use a generic list to store items inside the trigger and iterate across them every frame if needed.
     
  3. littlewombat

    littlewombat

    Joined:
    Feb 11, 2015
    Posts:
    13
    in general I want to do aoe spells so my idea is to do some objects with colliders (spells) then in player's scripts check if player is in this collider or not. There are many spells (~100) so this way have to check 100 colliders in every frame? do you think that should i do it with ontriggerenter/exit or not?
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Collider checking is relatively optimised by PhysX. The system doesn't check every collider every frame, but uses some very clever partitioning techniques to eliminate collisions that can't possibly happen.
     
  5. littlewombat

    littlewombat

    Joined:
    Feb 11, 2015
    Posts:
    13
    So I will try to use ontriggerenter/exit, thanks man!