Forums › 💬 NodeCanvas › 🤩 Custom Nodes and Tasks › extended InstantiateGameObject action › Reply To: extended InstantiateGameObject action
Modified it again, to include better info when parenting under a BB variable, and instantiating directly under the parent, instead of changing the hierarchy (a potentially expensive operation).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
using NodeCanvas.Framework; using ParadoxNotion.Design; using UnityEngine; namespace NodeCanvas.Tasks.Actions { [Category("GameObject")] public class InstantiateGameObject : ActionTask<Transform> { public BBParameter<Transform> parent; public BBParameter<Vector3> clonePosition; public BBParameter<Vector3> cloneRotation; [BlackboardOnly] public BBParameter<GameObject> saveCloneAs; protected override string info { get { string parentName; if (parent.value || parent.useBlackboard) parentName = parent.ToString(); else parentName = "World"; if (saveCloneAs.useBlackboard) return string.Format("Instantiate {0} under {1} at {2} as {3}", agentInfo, parentName, clonePosition, saveCloneAs); else return string.Format("Instantiate {0} under {1} at {2}", agentInfo, parentName, clonePosition); } } protected override void OnExecute() { var clone = Object.Instantiate(agent.gameObject, parent.value, false); clone.transform.position = clonePosition.value; clone.transform.eulerAngles = cloneRotation.value; saveCloneAs.value = clone; EndAction(); } } } |