public void SetGun(VehiclePartContext partContext) { tasks.Enqueue(delegate { contextStorage[nameof(GunBuilder)] = partContext; Transform existPart = parts.GetGun(); if (existPart != null) { DestroyImmediate(existPart.gameObject); } GameObject res = InstantiatePart((GameObject)partContext.GetPrefabDirectly(), "Gun"); var gunBuilder = res.AddComponent <GunBuilder>(); }); }