Tag is not defined when detecting it with RayCast2D even though it was already set up and assigned.

This is the script, basically it detects objects near the player, in this case it’s trying to detect nearby objects. The tag I am detecting is called “Pushable Object”. When I use Debug.Log to print out the tag the RayCasts were detecting, they were printing “Pushable Object”, but when I try to compare it using another if statement inside with CompareTag, it stops working and says that the “Pushable Object” tag is not defined. Even if I try to use other methods by directly comparing the tag with a string, it still doesn’t work (though that doesn’t print out an error).
(Note: The tag is correctly set up in the project settings and assigned to the correct object)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerNearbyObjectDetection : MonoBehaviour
{
    public bool pushableObjectAtLeft;
    public bool pushableObjectAtRight;
    public bool pushableObjectAtTop;
    public bool pushableObjectAtBottom; 

    void Update() 
    {
        RaycastHit2D leftRayCast = Physics2D.Raycast(transform.position, Vector2.left, 1f); 
        RaycastHit2D rightRayCast = Physics2D.Raycast(transform.position, Vector2.right, 1f);
        RaycastHit2D topRayCast = Physics2D.Raycast(transform.position, Vector2.up, 1f); 
        RaycastHit2D bottomRayCast = Physics2D.Raycast(transform.position, Vector2.down, 1f); 
        if (leftRayCast.collider != null)
        {
            pushableObjectAtLeft = true; 
        }
        else
        {
            pushableObjectAtLeft = false; 
        }
        if (rightRayCast.collider != null) 
        {
            Debug.Log(rightRayCast.collider.transform.gameObject.tag); 
            if (rightRayCast.collider.transform.gameObject.CompareTag("Pushable Object"))
            {
                Debug.Log("Correctly detected tag"); 
                pushableObjectAtRight = true;
            }
        }
        else
        {
            pushableObjectAtRight = false; 
        }
        if (topRayCast.collider != null)
        {
            pushableObjectAtTop = true;
        }
        else
        {
            pushableObjectAtTop = false; 
        }
        if (bottomRayCast.collider != null)
        {
            pushableObjectAtBottom = true;
        } 
        else
        {
            pushableObjectAtBottom = false; 
        }
    }
}

Is there any way I can fix this and have it detect the tag correctly?

You didn’t post a screenshot of the log, so it’s hard to say with any authority, but it’s probably a typo somewhere you’re overlooking – maybe even a trailing space if Unity doesn’t trim them by default – try wrapping the log statement in something more obvious, like !!tag!! or something so you can see exactly what it’s set to.

I have a screenshot of the log here. Can you see the problem?

7555699--934294--Log.jpg

Are you sure you don’t have whitespace anywhere? Like space at the beginning or at the end of the tag?
These are the same tag but different prefix and suffix spaces:
7555756--934306--screenshot.png

What happens if you change your tag to PushableObject and then do the CompareTag using that?
Just wondering if a tag can only be a single word as that is how they seem to be talked about in the manual (and all the examples show only tags without spaces in between the words).

Thank you! There was a space at the end that I did not notice.