Unity thinks is an Object…not a GameObject so things like AddComponent do not work.
There are three different icons in the project
I’ve got a blue box (cow)
and a blue box with a paper on it.(cowold) works
and the grey box (jeep)doesn’t work.
The blue box with papers load fine using that code.
The grey box type does not.
Anyway I’m totally failing at this prefab stuff after 2 days of fooling around.
A grey box is an empty prefab. A blue box with a paper is not really a prefab, it’s an asset. Only a blue box (no paper) is a proper prefab.
To make a prefab, do Create → Prefab. Then drag what you want onto it. It’s usually easiest to create game objects in the scene, then drag the object from the hierarchy view onto the empty prefab in the project view.
The blue box signifies that there is a single GameObject under the prefab (therefore the prefab and GameObject can be treated as essentially the same thing). When you place two GameObjects at the root of a prefab you get the grey box because the prefab doesn’t represent a single GameObject. If you want to be able to load the prefab as a single GameObject then you should parent your two objects under one root and then put that root object in the prefab.
To answer your questions in the second post:
You can generate a prefab from an asset, but that’s what Unity does internally anyway. When you import an asset Unity generates a GameObject which contains the contents of that asset. Therefore you can generate a prefab with an asset, but it’ll just be the same as the GameObject auto generated by Unity.
Object.Instantiate returns and Object, so it needs to be cast to a GameObject.