#if GRAPH_DESIGNER /// --------------------------------------------- /// Behavior Designer /// Copyright (c) Opsive. All Rights Reserved. /// https://www.opsive.com /// --------------------------------------------- namespace Opsive.BehaviorDesigner.Runtime.Tasks.Actions.GameObjectTasks { using Opsive.GraphDesigner.Runtime.Variables; using UnityEngine; [Opsive.Shared.Utility.Category("GameObject")] [Opsive.Shared.Utility.Description("Gets a component from a GameObject using the string component type name.")] public class GetComponent : TargetGameObjectAction { [Tooltip("The component type name (e.g., 'Rigidbody', 'Camera', 'Transform').")] [SerializeField] protected SharedVariable m_ComponentType; [Tooltip("The retrieved component.")] [RequireShared] [SerializeField] protected SharedVariable m_StoreResult; /// /// Executes the action logic. /// /// The status of the action. public override TaskStatus OnUpdate() { if (string.IsNullOrEmpty(m_ComponentType.Value)) { return TaskStatus.Success; } var componentType = Opsive.Shared.Utility.TypeUtility.GetType(m_ComponentType.Value); if (componentType == null) { Debug.LogError($"Error: The Type {m_ComponentType} cannot be found."); return TaskStatus.Success; } m_StoreResult.SetValue(m_ResolvedGameObject.GetComponent(componentType)); return TaskStatus.Success; } /// /// Resets the action values back to their default. /// public override void Reset() { base.Reset(); m_ComponentType = string.Empty; m_StoreResult = null; } } } #endif