---
tags:
    - "Has"
    - "Includes"
    - "Find"
    - "Search"
    - "Any"
    - "List"
    - "Array"
---

# Collection Contains Game Object

[Collections](index.md) / **Collection Contains Game Object**

<div class="grid cards" markdown>

* :green_circle: Can Read

* :red_circle: Cannot Write

</div>

## Description

Returns True if the collection has the specified Game Object among its items

## Parameters

| Name | Description |
| :--- | :---------- |
| Collection | The collection whose items are searched |
| Game Object | The Game Object reference searched for |

## Code

```cs
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Pool;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]

    [Title("Collection Contains Game Object")]
    [Category("Collections/Contains Game Object")]

    [Description("Returns True if the collection has the specified Game Object among its items")]
    [Image(typeof(IconStack), ColorTheme.Type.Teal, typeof(BadgeCubeOutline))]

    [Parameter("Collection", "The collection whose items are searched")]
    [Parameter("Game Object", "The Game Object reference searched for")]

    [Keywords("Has", "Includes", "Find", "Search", "Any", "List", "Array")]

    [Serializable]
    public class TypeBoolCollectionContainsGameObject : TypeBool
    {
        [SerializeField] private GetCollectionGameObjects m_Collection = new GetCollectionGameObjects();
        [SerializeField] private GetGameObject m_GameObject = new GetGameObject();

        public override bool Get(Args args)
        {
            GameObject gameObject = this.m_GameObject.Get(args);
            if (gameObject == null) return false;

            List<GameObject> buffer = ListPool<GameObject>.Get();

            try
            {
                this.m_Collection.Get(args, buffer);

                bool contains = buffer.Contains(gameObject);

                return contains;
            }
            finally
            {
                ListPool<GameObject>.Release(buffer);
            }
        }

        public override string ToString()
        {
            return $"{this.m_Collection} contains {this.m_GameObject}";
        }

        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
```

