Search code examples
unity-game-engine2dgame-physics

Unity - Newly created Layer for platforms not present in 'What Is Ground' field for Character Controller script 2D


I am following a basic tutorial for creating a 2D game using Unity. I am familiar with .Net/C#, but Unity and game development is relatively new for me.

I have created platforms that I wish the character (player) not to fall through, but rather to be able to walk on, jump on etc.

The instructions say to create a new layer for these platforms, ensure that sorting layer is not the one the player object uses, then - in the character controller script 2D - set the value for 'What is Ground' to the sorting layer for the platforms.

I was able to create a new sorting layer no issues, but the newly created sorting layer does not appear as an available layer in the What Is Ground field?

My new layer is called foreground, however only the default layers seem to be visible within Unity?

See screenshot:


Solution

  • I'm pretty sure you are talking about this CharacterController2D tutorial.

    There they use a

    public LayerMask whatIsGround;
    

    It is a LayerMask. They are for Layers not Sorting Layers


    From your question description it seems that you added a SortingLayer

    SortingLayer allows you to set the render order of multiple sprites easily. There is always a default SortingLayer named "Default" which all sprites are added to initially. Added more SortingLayers to easily control the order of rendering of groups of sprites. Layers can be ordered before or after the default layer.

    instead of a Layer

    Layers are most commonly used by Cameras to render only a part of the scene, and by Lights to illuminate only parts of the scene. But they can also be used by raycasting to selectively ignore colliders or to create collisions.


    => Make sure to add a Layer.