I’m getting this weird red error when I try to set the layer mask with the following code
[SerializeField] private GameObject _rayCastOPGameObj;
[SerializeField] private GameObject _rayCastEDGameObj;
[SerializeField] private LayerMask whatisTheGroundFG;
public bool _checkGrounded = false;
void Start()
{
whatisTheGroundFG = LayerMask.GetMask("Platforms"); //<~ RED ERROR!
}
void LineRayCast_CheckGround()
{
gameObject.layer = whatisTheGroundFG; //<~ RED ERROR !
_checkGrounded = Physics2D.Linecast(_rayCastOPGameObj.transform.position, _rayCastEDGameObj.transform.position, 1 << whatisTheGroundFG.value);
}
This doesn’t work either
gameObject.layer = whatisTheGroundFG.value;
gameObject.layer = (int)whatisTheGroundFG;
This does work… aren’t LayerMasks integers?
gameObject.layer = 1;
Here is the red error
A game object can only be in one layer. The layer needs to be in the range [0...31]
0x00007ff65c0a7bcc (Unity) StackWalker::GetCurrentCallstack
0x00007ff65c0adf49 (Unity) StackWalker::ShowCallstack
0x00007ff65c8a5e13 (Unity) GetStacktrace
0x00007ff65d7dacba (Unity) DebugStringToFile
0x00007ff65ba38a3f (Unity) GameObject::SetLayer
0x00007ff65c1e1fe7 (Unity) GameObject_Set_Custom_PropLayer
0x00000230b9a70139 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.GameObject:set_layer (UnityEngine.GameObject,int)
0x00000230b9b4f753 (Mono JIT Code) [GroundCheck.cs:110] GroundCheck:LineRayCast_CheckGround ()
0x00000230b9b4f253 (Mono JIT Code) [GroundCheck.cs:63] GroundCheck:FixedUpdate ()
0x000002316ddd63c8 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007ffdd4d5e670 (mono-2.0-bdwgc) [mini-runtime.c:2816] mono_jit_runtime_invoke
0x00007ffdd4ce2af2 (mono-2.0-bdwgc) [object.c:2921] do_runtime_invoke
0x00007ffdd4cebb4f (mono-2.0-bdwgc) [object.c:2968] mono_runtime_invoke
0x00007ff65bff1b84 (Unity) scripting_method_invoke
0x00007ff65bfed1f1 (Unity) ScriptingInvocation::Invoke
0x00007ff65bfbd5f4 (Unity) MonoBehaviour::CallMethodIfAvailable
0x00007ff65bfbd6fc (Unity) MonoBehaviour::CallUpdateMethod
0x00007ff65bb42288 (Unity) BaseBehaviourManager::CommonUpdate<FixedBehaviourManager>
0x00007ff65bb482da (Unity) FixedBehaviourManager::Update
0x00007ff65bd3a7e3 (Unity) `InitPlayerLoopCallbacks'::`2'::FixedUpdateScriptRunBehaviourFixedUpdateRegistrator::Forward
0x00007ff65bd23f0c (Unity) ExecutePlayerLoop
0x00007ff65bd23fe3 (Unity) ExecutePlayerLoop
0x00007ff65bd29139 (Unity) PlayerLoop
0x00007ff65c4a9891 (Unity) PlayerLoopController::UpdateScene
0x00007ff65c497cf9 (Unity) PlayerLoopController::EnterPlayMode
0x00007ff65c4a5051 (Unity) PlayerLoopController::SetIsPlaying
0x00007ff65c4a80c5 (Unity) Application::TickTimer
0x00007ff65c8abb41 (Unity) MainMessageLoop
0x00007ff65c8af776 (Unity) WinMain
0x00007ff65e416e62 (Unity) __scrt_common_main_seh
0x00007ffe22a67034 (KERNEL32) BaseThreadInitThunk
0x00007ffe24322651 (ntdll) RtlUserThreadStart