Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Collision code sample not working
#1
I copied the script example to do collision test. and unity says it can't convert out from the collider

Assets/Scripts/GrabRope.cs(33,64): error CS1503: Argument `#2' cannot convert `out UnityEngine.Collider' expression to type `out UnityEngine.Component'


 Collider collider;
if (ObiCollider.idToCollider.TryGetValue(contact.other,out collider)){
// do something with the collider.
}


i looked at CollisionEventHandler and it uses Component collider;  is that what it should be? 

all i know is its not working. trying for a long time today to code a grab the rope script
Reply
#2
(08-12-2018, 06:38 AM)aphixe Wrote: I copied the script example to do collision test. and unity says it can't convert out from the collider

Assets/Scripts/GrabRope.cs(33,64): error CS1503: Argument `#2' cannot convert `out UnityEngine.Collider' expression to type `out UnityEngine.Component'


 Collider collider;
if (ObiCollider.idToCollider.TryGetValue(contact.other,out collider)){
// do something with the collider.
}


i looked at CollisionEventHandler and it uses Component collider;  is that what it should be? 

all i know is its not working. trying for a long time today to code a grab the rope script

For 3.3 and up the "collider" variable should be of type Component, as the idToCollider dictionary stores components, not colliders. We will correct the documentation asap. Thanks for pointing this out!
Reply