Adding Prefab Components

I need to add a prefab gameobject as a component to another gameobject via scripting, but am having problems. I’ve tried using the AddComponent function and been able to add blank gameobjects this way. I’ve also been able to add various custom scripts this way. However, I have been completely unable to add prefab gameobjects in this fashion. Neither a type parameter nor a string parameter will find any prefabs, and AddComponent won’t take straight references (unlike Instantiate).

This is a major problem for my project; it seems like prefab components ought to be a logical, integral functionality of unity’s prefab system, but I cannot find a command to make it work. Does anyone know how to do this?

Thanks,

C.

A Prefab is a GameObject. a Component is anything (MonoBehaviours mostly) that attaches to GameObjects. Therefore, a Prefab cannot be a Component, and could never be used as a parameter in AddComponent().

Are you confusing "adding a Prefab to a GameObject" with parenting a prefab to a GameObject? Because that's as simple as setting the transform.parent, eg:

myNewObject : GameObject = Instantiate(myPrefab, pos, rot);
myNewObject.transform.parent = gameObjectIWantToParentTo.transform;