Problem Destroying Component
Hello, I have run into an error that I've never encountered before. This is my code. I have tried both scenarios and I get the same error:
NetworkBehaviour[] nB = gO.GetComponents<NetworkBehaviour>();
for (int i = 0; i < nB.Length; i++)
{
NetworkBehaviour n = nB[i];
Destroy(n);
}
and this:
NetworkBehaviour[] nB = gO.GetComponents<NetworkBehaviour>();
for (int i = 0; i < nB.Length; i++)
{
Destroy(nB[i]);
}
The error I am getting is this:
Destroying assets is not permitted to avoid data loss. If you really want to remove an asset use DestroyImmediate (theObject, true); UnityEngine.Object:Destroy(Object) MyCharacter.Networking.SetUpLocalPlayerDestroyer:Start() (at Assets/MyAssets/Scripts/Game/Multiplayer/SetUpLocalPlayerDestroyer.cs:86)
What am I doing wrong and how can I fix it? If it helps, I am using Unity 2017.3 on windows 10. I have heard that DestroyImmediate() can cause problems, and am not sure why I am getting this anyway. I thought this was when I am trying to destroy an asset, I am certain that's not what i'm doing.