public static GenericOperator CreateGenericOperator(OperatorData data) { Vector3 position = new Vector3(); List <GenericOperator> parents = new List <GenericOperator>(); List <GameObject> prefabList = obs.GetOperatorPrefabs(); foreach (var prefab in prefabList) { if (data.name == prefab.name) { parents = new List <GenericOperator>(); position = new Vector3(data.posX, data.posY, data.posZ); int parentID = 0; foreach (var child in obs.GetOperators()) { parentID = child.Id; if (parentID == data.parent) { parents.Add(child.GetComponent <GenericOperator>()); break; } } GameObject go = obs.CreateOperator(prefab, parents); GenericOperator op = go.GetComponent <GenericOperator>() ?? go.AddComponent <GenericOperator>(); //waiting for one frame, due to generating icons and children instance.StartCoroutine(instance.SetIconLocation(op, position)); instance.StartCoroutine(instance.DestroyNewOperatorChildren(op.Children)); op.Id = data.ID; op.LoadSpecificData(data); operatorList.Add(op); return(op); } } return(null); }