Documentation index for AI agents (llms.txt) A Markdown version of every page is available: request the page's source under /docs/, follow the "alternate" link in this page's head, or start from /llms.txt.
Visual Script logo Manual

With Component#

Game Object / With Component

  • Can Read

  • Cannot Write

Description#

The collection of every loaded Game Object that has the specified Component attached

Parameters#

Name Description
Type The Component type every collected Game Object has attached
Include Inactive Whether Game Objects that are not active are also collected

Code#

using System;
using System.Collections.Generic;
using UnityEngine;
using VisualScript.Icons;
using Object = UnityEngine.Object;

namespace VisualScript.Runtime
{
    [Get]

    [Title("With Component")]
    [Category("Game Object/With Component")]

    [Description("The collection of every loaded Game Object that has the specified Component attached")]
    [Image(typeof(IconCubeSolid), ColorTheme.Type.TextLight, typeof(BadgeMagnifier))]

    [Parameter("Type", "The Component type every collected Game Object has attached")]
    [Parameter("Include Inactive", "Whether Game Objects that are not active are also collected")]

    [Keywords("Search", "Find", "Scene", "Type", "Behaviour", "Script")]

    [Serializable]
    public class TypeCollectionGameObjectsWithComponent : TypeCollectionGameObjects
    {
        // EXPOSED MEMBERS: -----------------------------------------------------------------------

        [SerializeField] private TypeReferenceComponent m_Type = new TypeReferenceComponent();
        [SerializeField] private GetBool m_IncludeInactive = new GetBool(false);

        // PUBLIC METHODS: ------------------------------------------------------------------------

        public override void Get(Args args, List<GameObject> values)
        {
            values.Clear();

            Type type = this.m_Type.Type;
            if (type == null) return;

            FindObjectsInactive includeInactive = this.m_IncludeInactive.Get(args)
                ? FindObjectsInactive.Include
                : FindObjectsInactive.Exclude;

            Object[] objects = Object.FindObjectsByType(type, includeInactive);

            foreach (Object instance in objects)
            {
                if (instance is Component component) values.Add(component.gameObject);
            }
        }

        public override string ToString()
        {
            return $"With {this.m_Type}";
        }

        // PROTECTED METHODS: ---------------------------------------------------------------------

        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.