Search Unity

Old Lessons are easy to forget, example #352. OnTriggerEnter.

Discussion in 'General Discussion' started by halley, Nov 16, 2022.

  1. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,443
    I was working on a script similar to one that I wrote and misplaced long ago, and had to relearn the Rigidbody requirement. Why oh why can't a trigger detect a collider without a Rigidbody?

    Code (CSharp):
    1.         void OnTriggerEnter(Collider collider)
    2.         {
    3.             //
    4.             // Hey, not detecting a collider you thought it should?
    5.             // Unity Physics requires both parties to have Rigidbody
    6.             // and collisions enabled between their layer and our layer.
    7.             // Also, the Physics option for allowing kinematic-kinematic
    8.             // or kinematic-static collisions may be required.
    9.             //
    10.  
    Reminder comments for lessons re-learned are better than nothing. I better not lose this script too.

    What's your oh-yeah-I-keep-forgetting "feature" of Unity?
     
  2. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,698
    The gotcha I relearned approximately three times: That
    Input.GetKeyDown
    will only give True reliably in the Update() method (or a Coroutine), but not in FixedUpdate because it's bound to frames.
     
    halley likes this.
  3. BIGTIMEMASTER

    BIGTIMEMASTER

    Joined:
    Jun 1, 2017
    Posts:
    5,181
    some months ago, i started making a scrivener project where i can categorizes stuff like this - basically like creating my own documentation sort of. Mostly it's just short notes and links. Lots of code snippets.

    I keep it in a git repo too so it's not just local.

    there is a million apps you could use for something like this but i liked scrivener because it has robust search features, organization features, and great ergonomics (like you can navigate whole thing easily using keyboard only)