Trouble adding new layers to CameraRaycaster.cs layerPriorities

[Problem]
I am trying to add 2 new layers to the RayCast detection layers used by the CameraRaycaster.cs script. But only the Walkable and Enemy layers seem to be detected.

[What I Did]
I added the 2 layers to the tags and layers inspector panel
Player = LayerMask 10
Friendly = LayerMask 11

Added 2 new items to the scene with colliders and set the layers for the new layers.

I edited Utility.cs and added 2 lines to the emu:

public enum Layer {
Walkable = 8,
Enemy = 9,
Player = 10,
Friendly = 11,
RaycastEndStop = -1
};

I added the following edit to the layerPriorities in CameraRaycaster.cs:

public Layer[] layerPriorities = {
Layer.Enemy,
Layer.Walkable,
Layer.Friendly,
Layer.Player
};

[Conclusion]
Removed the component from the camera and added the component back to see if it would solve.
I searched the Unity community for answers but found no help.
I ensured all the boxes in the Physics Matrix for the 2 layers were checked.
Reversed the order of the layers in the Tags and Layers inspector panel placing Player at layer 8 and Friendly at layer 9 and the detection worked for only those 2 layers and not the Walkable or Enemy layers.

[Insight]
I am thinking its has something to do with the bitShitf and the double digits and will continue further testing and troubleshooting.

I think you need to re-order your Layer array, make sure Walkable is at the bottom.

public Layer[] layerPriorities = {
Layer.Enemy,
Layer.Friendly,
Layer.Player,
Layer.Walkable,
};

In your version, if you have a Friendly on a walkable the CameraRaycaster script will loop through you array and match the walkable first and ignore the Friendly. In my version the Friendly will get hit first.

1 Like

That did the trick, But keep in mind you have to change the order of the layers in the CameraRaycaster component properties also. Editing the script had no effect until I changed the layer order in the Inspector for the Camera.CameraRaycaster.cs. Now it all works

.

Privacy & Terms