Im working on modular space ships, customizable by the player. A ship has hardpoints, which hold modules, which in turn can hold more modules, etc. etc.
The code of a hardpoint at this moment looks very simple;
public class Hardpoint : MonoBehaviour {
public GameObject holds;
public ComponentObject.Type[] canHold;
//public int id;
private GameObject heldInstance;
public void SpawnComponent() {
Debug.Log("SpawnComponent Called.");
Clear();
heldInstance = Instantiate(holds, transform.position, transform.rotation) as GameObject;
heldInstance.transform.SetParent(transform);
}
public void RollThroughDecompression(CompressedComponent c) {
Debug.Log("Rolling through Decompression.");
heldInstance.GetComponent<ComponentObject>().Decompress(c);
}
public void Clear() {
foreach (Transform child in transform)
{
Destroy(child.gameObject);
}
}
}
however, it all acts like it’s a prefab. because error messages i’m getting are:
Destroying assets is not permitted to avoid data loss.
If you really want to remove an asset use DestroyImmediate (theObject, true);
and
Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.
I’m completely lost at this point.