---
tags:
    - "Collider"
---

# On Collision Enter 2D

[Physics 2D](index.md) / **On Collision Enter 2D**

## Description

Executed when a game object collides with another collider with a Rigidbody2D

## Code

```cs
using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Title("On Collision Enter 2D")]
    [Image(typeof(IconCollision), ColorTheme.Type.Lime, typeof(BadgeArrowRight))]
    
    [Description("Executed when a game object collides with another collider with a Rigidbody2D")]
    [Category("Physics 2D/On Collision Enter 2D")]
    
    [Keywords("Collider")]

    [Serializable]
    public class TriggerCoreCollisionEnter2D : TriggerHandleSourceBase<HandleOnCollisionEnter2D>
    {
        // EXPOSED MEMBERS: -----------------------------------------------------------------------

        [SerializeField]
        private TValueOrAny<GetGameObject> m_Collide = new TValueOrAny<GetGameObject>();
        
        // PROPERTIES: ----------------------------------------------------------------------------

        protected override string GetTitle(GameObject source) => $"{this.SourceName} Collision Enter {this.m_Collide}";

        // OVERRIDE METHODS: ----------------------------------------------------------------------
        
        protected override void OnTrigger(GameObject target)
        {
            using Args args = Args.Get(this.Component, target);
            if (this.m_Collide.IsSpecific && this.m_Collide.Value.Get(args) != target) return;
            
            this.Run(args);
        }
    }
}
```

