I was finally able to figure out and reproduce my rayCasting error in UnitActionSystem. If you forget to remove the Visual component Collider of the Unit gameobject and later update the Unit as a prefab, then select “change the children” it will cause the collider on the component to also contain the Unit’s layer mask allowing that collider to be selected (near the feet of the Unit where the visual’s collider extends out.) Using TryGetComponent will then say true, I guess because the collider component is attached to the Unit, but it will send back Null because the collider component is not actually the Unit. So to fix this I had to check for null.
You had a Collider in the visual? A Mesh Collider?
Yeah the logic assumes the only things on the Unit layer with a collider are objects that have the Unit component.
Correct, the visual had a mesh collier on it; It was there when I created the Quad game object; I just forgot to remove it when I recreated the game.
I am not exactly sure what you mean on the last line: are you saying: the logic assumes the only things on the unit layer are Unit game objects and/or it’s components that have a collider that is also assigned to the unit layer mask?
Yes it will only hit things with the collider and on that layer.
The Raycast only hits colliders, so it’s not a problem if multiple objects are on the Units layer as long as they don’t have colliders.