Adding Components to a premade prefab.

So I got an asset from the asset store, and I wanted to add a script to one of the prefabs that came with the assets, so I can call it from my gun model so it shoots the prefab, but when I shoot it doesn’t move cause it doesn’t have my movement script and I can’t add it to the prefab from the asset list, and if I drag the prefab into the game and add the script to it my gun will just use the prefab from the asset list, not the in-game prefab. Please help.

You can click prefab, which will Inspector display its properties. Then you can add components straight from the inspector.

But that doesn’t work because the game will shoot the premade prefab in my asset list which I can’t add a script to.

You can click things in the asset list and add components to them.
Click the thing in the asset list, go to inspector, press “add component” button at the bottom of the inspector…

See in the picture there is no add component button, so I can’t add anything, and I want to add a script to the prefab in the project list,

not the hierarchy.

select it from hierarchy, add/edit and then hit apply

You’re trying to add a component to an imported MESH. The reason why you can’t add components to it is because it is not a prefab. Even if you could add data to it, it would’ve been wiped the moment you reimport the mesh.

Make an empty GameObejct, attach a mesh to it as a prefab, drag the resul into project folders, creating a prefab, then you’ll be able to add stuff to it.


On the screen- MeshObj in Project windows is the prefab, MeshObj in hierarchy is instance of that prefab, and Cube23 is the imported mesh which was attached to MeshObj as a child.

3 Likes

Thanks it worked : )