How to collide gameobject that is a child of a canvas and a gameobject that is not attach to canvas?

Is it possible to collide a gameobject that is attach to a canvas to another gameobject that is not attach to a canvas? (trying to use OnTriggerEnter2d)

To detect collisions between a game object that is a child of a Canvas and a game object that is not attached to the Canvas in Unity, you can use Unity’s built-in physics system.

Add a Rigidbody component to the non-canvas game object.
Set the Rigidbody’s “isKinematic” property to false, if it’s not already.
Add a Collider component to both game objects.
Make sure the Collider component on the non-canvas game object has the “isTrigger” property checked.
Write a script that attaches to the non-canvas game object, and in the OnTriggerEnter() method, check for collisions with the child objects of the Canvas. You can use the Transform.GetComponentInChildren() method to get the child objects of the Canvas.
Here is an example script that you can attach to the non-canvas game object:
public class CollisionDetector : MonoBehaviour
{
private void OnTriggerEnter(Collider other)
{
// Check if the collided object is a child of the canvas
if (other.transform.IsChildOf(transform.parent))
{
// Handle the collision
Debug.Log(“Collision detected!”);
}
}
}

This script checks if the collided object is a child of the parent of the non-canvas game object. If it is, it logs a message to the console.

Note: If the non-canvas game object has a Collider component that is not set to “isTrigger”, it will collide with other game objects that have Rigidbody components. If you don’t want this behavior, you can remove the Rigidbody component from the non-canvas game object.