Tiles not swapping in Build

Hello so as you can see in the video im making a game where when you jump the tiles switch. when you jump the box collider should enable and disable but the problem is that in the build it doesnt do that it only disables and enables the box collider.

here is the code:

using UnityEngine;
using UnityEngine.Tilemaps;

public class Movement : MonoBehaviour
{  
    public TileBase tile;
    public TileBase tileGrid;
    bool isRed = true;
    private float horizontal;
    public float speed = 8f;
    public float jumpingPower = 16f;
    private bool isFacingRight = true;
    public GameObject redTiles;
    public GameObject blueTiles;
     Tilemap redMap;
    Tilemap blueMap;
    TilemapCollider2D colRed;
    TilemapCollider2D colBlue;

    [SerializeField] private Rigidbody2D rb;   
    [SerializeField] private Transform groundCheck;
    [SerializeField] private LayerMask groundLayer;

    void Start() {
       
        redTiles = GameObject.Find("RedGrid");
        blueTiles = GameObject.Find("BlueGrid");

        redMap = redTiles.GetComponent<Tilemap>();
        blueMap = blueTiles.GetComponent<Tilemap>();

        colRed = redTiles.GetComponent<TilemapCollider2D>();
        colBlue = blueTiles.GetComponent<TilemapCollider2D>();
    }
    void Update()
    {  
        horizontal = Input.GetAxisRaw("Horizontal");

        if (Input.GetButtonDown("Jump") && IsGrounded())
        {          
            rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
        }
        if (Input.GetButtonUp("Jump") && rb.velocity.y > 0f)
        {
            rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
        }
        if (Input.GetButtonDown("Jump"))     
        {
            FlipTiles();
        }
        Flip();
    }
    private void FlipTiles(){
        isRed = !isRed;

        colRed.enabled = isRed;
        colBlue.enabled = !isRed;

        if(isRed){
            redMap.SwapTile(tileGrid,tile);
            blueMap.SwapTile(tile,tileGrid);
        }else{
            redMap.SwapTile(tile,tileGrid);
            blueMap.SwapTile(tileGrid,tile);
        }
    }

    private void FixedUpdate()
    {
        rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
    }

    private bool IsGrounded()
    {
        return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
    }

    private void Flip()
    {
        if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
        {
            isFacingRight = !isFacingRight;
            Vector3 localScale = transform.localScale;
            localScale.x *= -1f;
            transform.localScale = localScale;
        }
    }
}

Start with the device logs. You’re probably getting an exception or some other error.

When you do crazy ninja code like this:

You are setting yourself up for runtime mayhem and disaster.

Remember the first rule of GameObject.Find():

Do not use GameObject.Find();

More information: https://starmanta.gitbooks.io/unitytipsredux/content/first-question.html

More information: https://discussions.unity.com/t/899843/12

In general, DO NOT use Find-like or GetComponent/AddComponent-like methods unless there truly is no other way, eg, dynamic runtime discovery of arbitrary objects. These mechanisms are for extremely-advanced use ONLY.
If something is built into your scene or prefab, make a script and drag the reference(s) in. That will let you experience the highest rate of The Unity Way™ success of accessing things in your game.

“Stop playing ‘Where’s GameWaldo’ and drag it in already!”

Hello, I have removed all the GameObject.Find() and GetComponent<>() functions but the problem still continues.
I have tried many things such as deleting the library folder, thank you for your help.

Have you looked at the player.log to see if any errors are firing in a build?

Nonetheless the swapping should probably be moved onto a new component for the each of the red and blue grid tilemaps. Perhaps give a way for them to hook into your player to know when they jump.

Most straightforward way would be to just have a global delegate for when your player jumps:

public static event System.Action OnPlayerJumped;

When the player jumps, you can invoke the delegate:

if (Input.GetButtonDown("Jump"))   
{
    OnPlayerJumped?.Invoke();
}

Then you can make a component for your tilemap(s) that listen to it:

public class TileMapSwapper : Monobehaviour
{
    private void Awake()
    {
        Movement.OnPlayerJumped += HandleOnPlayerJumped;
    }
  
    private void OnDestroy()
    {
        // remember to unsubscribe!
        Movement.OnPlayerJumped -= HandleOnPlayerJumped;
    }
  
    private void HandleOnPlayerJumped()
    {
        // swap tiles in tilemap
    }
}

I tried this and unfortunately it still doesnt work in the build, I checked the Player.log and couldnt find anything. Could it be a problem in the rendering?

I finally found the problem, i changed the editor version to 2022.3.25f1