Can variable in an object be passed to another object as a method argument?

Bricks class is calling a method in Class Monitor, with fields passed in as arguments to the method. Bricks script is attached to an object in the scene and Monitor is attached to an Empty gameobject. I get the following runtime error:

Apreciate any advice and suggestion.

Thanks!

Error

MissingComponentException: There is no ‘SpriteRenderer’ attached to the “Monitor” game object, but a script is trying to access it.
You probably need to add a SpriteRenderer to the game object “Monitor”. Or your script needs to check if the component is attached before using it.
UnityEngine.SpriteRenderer.set_sprite (UnityEngine.Sprite value) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/SpritesBindings.gen.cs:247)
Monitor.collisionEngine (Int32 currentHits, Int32 maxHits, UnityEngine.GameObject gameObject, UnityEngine.Object[ ] sprite) (at Assets/Scripts/Monitor.cs:57)
Bricks.OnCollisionEnter2D (UnityEngine.Collision2D collision) (at Assets/Scripts/Bricks.cs:32)

public class Bricks : MonoBehaviour {
    public Sprite[] brickSprite;
    private int currentHits, maxHits;
    public void OnCollisionEnter2D(Collision2D collision)
    {
        Monitor brickMonitor = FindObjectOfType<Monitor>();
        brickMonitor.collisionEngine(currentHits, maxHits, gameObject, brickSprite);
    }

}

public class Monitor : MonoBehaviour {
    public void collisionEngine(int currentHits, int maxHits, GameObject gameObject, Object[] sprite)
    {
        LevelManager levelManager = FindObjectOfType<LevelManager>();

        if (++currentHits >= maxHits)
        {
            Destroy(gameObject);
            NumberOfBricks--;
        }
        else
        {
            if (sprite is Sprite[]) {
                GetComponent<SpriteRenderer>().sprite = (Sprite) sprite[currentHits - 1];
            }
          
        }

    }
    }

erm… I think you’re missing a SpriteRenderer, maybe adding one would help…

or if you’re trying to alter the sprite that’s been passed in, why are you trying to get the SpriteRenderer in the first place?

and architecturally, why does it look like you’re trying to remotely handle brick’s health rather than doing that inside the brick scripts?

I am trying to change the sprite of the gameobject that was passed in as the method’s argument.

brickMonitor.collisionEngine(currentHits, maxHits, gameObjec****t, brickSprite);

As there will be other objects’ health that will be handled similarly, I thought it may be a good idea to have a script to handle objects’ health (and sprite change) and attached it to other gameobjects as needed. Is there a better approach?

Thanks again !