Search Unity

Bug in Physics.Raycast?

Discussion in 'Physics' started by sickbattery, Jun 11, 2015.

  1. sickbattery

    sickbattery

    Joined:
    Jul 13, 2014
    Posts:
    20
    I get an exception on Physics.Raycast(ray, out hit) if the ray doesn't hit anything. Now I'm not a newbe, so please spare me with I'm not setting some variable or not checking for null ... it's truly the Physics.Raycast function that throws.

    It must be something with my code because I can use Physics.Raycast(any parameters) with a new project.

    ... but how am I supposed to find what is wrong when the exception is just silenced and not visible. The function just skips to the end.

    All I get in the immediate window:
    > Physics.Raycast(ray, out hit)

    System.ArgumentNullException: Value cannot be null.
    Parameter name: c
    at Mono.Debugger.Soft.TypeMirror.IsAssignableFrom(TypeMirror c)
    at SyntaxTree.VisualStudio.Unity.Debugger.Evaluation.ExpressionEvaluator.<>c__DisplayClass14.<GetMatchingMethod>b__11(ParameterInfoMirror p)
    at System.Linq.Enumerable.All[TSource](IEnumerable`1 source, Func`2 predicate)
    at SyntaxTree.VisualStudio.Unity.Debugger.Evaluation.ExpressionEvaluator.GetMatchingMethod(String name, IList`1 arguments, TypeMirror type)
    at SyntaxTree.VisualStudio.Unity.Debugger.Evaluation.ExpressionEvaluator.VisitInvocationExpression(InvocationExpression invocationExpression)
    at ICSharpCode.NRefactory.CSharp.InvocationExpression.AcceptVisitor(IAstVisitor visitor)
    at SyntaxTree.VisualStudio.Unity.Debugger.UnityExpression.<>c__DisplayClass2.<EvaluateAsync>b__0()
    at System.Threading.Tasks.Task`1.InnerInvoke()
    at System.Threading.Tasks.Task.Execute()


    I have no clue where to start!? What is this!?


    More Info (I posted accidently and now have to edit and edit and edit):
    I have an abstract base class which is based on MonoBehaviour it's called WorldObjectBase and it has a virtual Update() function that calls abstract methods for the state of the object ... like AppearingPhase(), GamePhase(), DisappearingPhase() ... my game objects have this script attached.

    Might that be the cause? IDK. I added something similar to an empty project and it also worked.

    Maybe you guys know what the TypeMirror null exception is indicating. What could be wrong with my classes or objects ... ?

    I thought ... well ok, I'm just not going to use Physics.Raycast and write some own code, but then ... what if this exception f**** up physics in general?

    My Objects have a collider ... I have an empty object as parent for instantiated objects (all with colliders) ... there are some without colliders but they are not instantiated, meaning not in game.

    I'm going insane XD ... I'm a professional full time C# programmer and I don't know what is wrong XD ... omg. ... but at the same time this kind of exception sounds like something internal. I can't post all my code here and I don't know which part of the code I should post ... so to me this is a Unity Bug.

    Oh ... yes. I'm using Unity 5.1.0f3 ? I had the same issues with 5.0 ...

    Btw. There is just my empty object in the scene which has a stage script that adds and removes instantiated prefabs that have a collider. With no instantiated objects -> exception. I moved the empty object out of the ray's way ... I just don't know what's going on -.- ...

    I'll try a new project tomorrow and I'll add my scripts and objects and Asset Store effects etc. one by one to see what is causeing this :( ... I'm just angry by now ... and this with a strict short schedule :( ...
     
    Last edited: Jun 11, 2015
  2. sickbattery

    sickbattery

    Joined:
    Jul 13, 2014
    Posts:
    20
    Ok ... so apperently you can't use the immediate window -.- ? I finally found out why I thought I'm getting an exception.

    The raycast function is working. I had no else statement in my "if" and since the function returned a false it just quit the function. I tried to run the raycast function in the immediate window (because I expected a hit) to see what the return value is, but got the above exception ... which is weird and not so smart ... ... but at least I know now that everything is fine and that I just shouldn't use the immediate window -.- ...
     
    Last edited: Jun 13, 2015