- Home /
Why cannot I drag and drop a gameObject from Hierarchy to a prefab's slot in the Inspector?
I have a game object prefab, say myPrefab.
On myPrefab, I have a script attached, which contains this line (I want myPrefab to follow ObjectToFollow, but that is irrelevant):
var ObjectToFollow: GameObject;
So now in the inspector, when I have myPrefab selected, under the aforementioned script theres: Object To Follow _______None (Game Object)
In the None (Game Object) field, I can drag and drop any other prefab.
I cannot however, drag and drop any game object from the Hierarchy into the None (Game Object) field. What should I do to put my gameObject to the Object To Follow slot in the Inspector?
The problem is that the ObjectToFollow is the main object of the game and it is already in the Hierarchy when the level begins.
I suppose theres something really basic that Im missing here.
Answer by Ejlersen · Dec 31, 2010 at 10:00 AM
Well, a prefab is a standard representation of a game object. If you dragged an object in from the scene, then it wouldn't be standard if you changed to a new scene.
Now that I come to think about it, what you say totally makes sense... I'll try to figure out another way of making things work. Thanks Ejlersen :-)
No problem. I think you could just apply the changes to your prefab, then it might follow your game object in the scene, since there is only one of them :)
I made a prefab of the ObjectToFollow and I dragged'n'dropped that prefab in the None(GameObject) slot. Unfortunately, even if it's the only ObjectToFollow prefab instance in the scene, myPrefab doesn't follow it (I know the script that does the following is correct, I have used it with simple game object versions of the prefabs). I'll try to resolve the problem by making myPrefab a child of ObjectToFollow.
Answer by pavlito · Oct 13, 2014 at 07:02 AM
Running a bit late with the answer, but, from what I gather you are trying to drag an object from the scene to myPrefab which is selected in the project view. This cannot be done. What you can do is make a prefab of the object that's in the scene and then drag that prefab to a myPrefab (now you can drag from project view to project view).
Hope this makes sense.
I specially logged in to upvote this answer. This worked for me. Thanks!
Answer by Chris 22 · Jan 02, 2011 at 09:26 PM
Can't you change
var ObjectToFollow: GameObject;
to
var ObjectToFollow:Transform;