Search Unity

Question DrawRay Not Showing On A Specific Gameobject (All Gizmos On)

Discussion in 'Editor & General Support' started by Bisqo, Apr 4, 2020.

  1. Bisqo

    Bisqo

    Joined:
    Dec 31, 2017
    Posts:
    4
    Hey all,

    first post here so I hope this is an ok spot to post this issue.

    I am casting rays and then (Trying to) drawing them. Nothing out of the ordinary here. I have gizmos on and can see all rays I cast on all gameobjects except for my player. At first I thought it was an issue with my script however, when I moved the script to just a basic capsule object I saw the rays fine. So it doesn't appear to be an issue with the script(s). Then I moved the script to an enemy in my test scene and once again I saw the rays perfectly fine. I just can not see the rays on my actual player. As I said above I have gizmos and every check mark turned on. The script works perfectly I just can't see the rays on my player character.

    Anyone else have this issue and found a solution?
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    Can you show the script that draws the gizmos?
     
  3. Bisqo

    Bisqo

    Joined:
    Dec 31, 2017
    Posts:
    4
    upload_2020-4-4_13-40-2.png

    Thank you for the reply! So after doing some digging the issue is not what I thought. The rays are being shown, however I found them several units below my character which is why I thought they weren't being shown. In short the rays are being shown, just not at the spot needed. Well below the origin spot.
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    In the future, please post code using Code tags, instead of pasting a screenshot of the code. And ideally edit your post to remove the screenshot and paste the code in Code tags.
     
  5. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    I'd say the most likely reason it's not behaving in certain cases if that you're not getting the expected Raycast Hit. Try to debug that code, to see if the hit isn't occurring. Or try Debug.Drawing the ray that you think you're casting, to see of it's in the right place.
     
  6. Bisqo

    Bisqo

    Joined:
    Dec 31, 2017
    Posts:
    4
    Ahh ok will do. Haven't posted code before so not sure even how to post it properly. I suppose its one of those code options in the tool bar though.

    It is hitting. It's hitting a platform my character is not on, a platform well below my character and not even on the surface of that platform. Its hitting within the well below platform.
     
  7. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    What if you add this to your code right before you call the Raycast:

    Code (CSharp):
    1. Debug.DrawRay(checkPosition, Vector2.down, Color.green);
    That should draw what the raycast is trying to cast. Is the green line in the right place?
     
  8. Bisqo

    Bisqo

    Joined:
    Dec 31, 2017
    Posts:
    4
    Yes the green is in the right place. It was still being cast way below my character as the other rays were. I just ended up creating a new test object to use in the meantime. I am pretty sure I am redoing all the art and animations I had done (not many). I've already spent a day and a half on this issue and don't really want to take more time to try and fix it when I am redoing the art anyway and the scripts work perfect on newly created objects. Not sure if this all ended up being a bug or something got messed up doing an update but no need to tear my hair out over it anymore haha

    I appreciate your help! Hopefully no one else has this issue!
     
    JoeStinky likes this.