Particles Inside ScrollRect Mask showing outside

So i have a shop where a player can buy particles for their swords. the only problem is that the shop doesnt extend the whole screen so when a player scrolls through the particles shop, the particles can be see outside of the Scroll rect. How can i make it so it stays inside and it isnt shown outside of it? I have tried the “Show only in mask” option in the particle system and that didnt do anything.

I know it is a bit late but I have the same problem and couldnt find a solution.

Check this out

I know it’s too late, but I’m adding that maybe it may be useful for someone.

using UnityEngine;

public class ParticleMaskController : MonoBehaviour
{
    public GameObject maskObject;
    private RectTransform maskRect;
    private ParticleSystem particles;
    private bool isPlaying;

    void Start()
    {
        maskRect = maskObject.GetComponent<RectTransform>();
        particles = GetComponent<ParticleSystem>();
    }

    void Update()
    {
        Vector3[] corners = new Vector3[4];
        maskRect.GetWorldCorners(corners);

        Vector3 bottomLeft = corners[0];
        Vector3 topRight = corners[2];

        bool isInsideMask = particles.transform.position.x > bottomLeft.x
            && particles.transform.position.x < topRight.x
            && particles.transform.position.y > bottomLeft.y
            && particles.transform.position.y < topRight.y;

        if (isInsideMask && !isPlaying)
        {
            particles.Play();
            isPlaying = true;
        }
        else if (!isInsideMask && isPlaying)
        {
            particles.Stop();
            isPlaying = false;
        }
    }
}

The above code takes a Gameobject named Maskobject and determines the masking area using its rectransform component. It is defined as mascobject public, so you can access it from outside.

Also, if it doesn’t work directly, I would like you to know, In the code, the mascobject variable holds the game object of the mask. However, this variable should not be of rectransform type. Instead, you need to change the mascobject variable to a Game Object representing the panel game object under the Canvas. The panel game object must have a mask component and have Scrollrect Game Object below.

After making these changes, the functionality of the code needs to improve. Particles should no longer be out of the mask and their movements in the playground should be limited within the limits of the mask.