- Home /
Cannot add or drag an asset to the inspector
Having a strange issue where the inspector won’t allow me to attach my enemy prefab. I can only attach it assuming it’s already in the hierarchy which obviously isn’t the correct solution given that we want it as a prefab.
As you can see in the screenshot Enemy is a Game Object already placed in the hierarchy but attempting to drag in a prefabbed object (enemyBlack2) isn't allowed.
I should also add that I attempted to run Unity in both standard and administrator modes.
Answer by ThePunisher · Jul 24, 2017 at 11:48 PM
It's possible that your EnemySpawner script is looking for a specific type of object. One that your instanced enemy qualifies as, but not the prefab. Mind attaching a snippet of the code declaring the EnemyPrefab member?
If I had to take a guess I'd say that you're looking for a specific type other than GameObject. And this specific type is something you're attaching to your Enemy instance in your scene Hierarchy, but it's not attached to the prefab. You could try creating the prefab from the Enemy instance in your scene by dragging it over to your asset view.
Right, or he dragged the wrong object. An imported FBX model imports as GameObject / prefab but also has the $$anonymous$$esh as sub asset. Dragging the $$anonymous$$esh of course won't work. I never use the two column mode of the project view so i'm not sure which of the two things is the gameobject.
public class EnemySpanwer : $$anonymous$$onoBehaviour {
public GameObject enemyPrefab;
// Use this for initialization
void Start () {
// instantiate returns an object but consider it as a gameobject
GameObject enemy = Instantiate(enemyPrefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
// change the enemies parent. transform of whatever the enemy transform is, in this case the EnemyFormation
enemy.transform.parent = transform;
}
I used the suggested workaround of dragging from the hierarchy to the asset and generating the prefab that way. This seems to be the best solution. The only snag was that I had to reattach a sprite to the enemy asset, by default it prefabbed a blank object.
Answer by JoaoGracio · Aug 15, 2017 at 05:49 PM
Im having the same problem how did you solve it InJust???
I used the suggested workaround of dragging from the hierarchy to the asset and generating the prefab that way. This seems to be the best solution. The only snag was that I had to reattach a sprite to the enemy asset, by default it prefabbed a blank object.