# Using Part of prefab as script parameter

I'm trying add a weapon to Eithan - the third person character. So I want to take his hand, which is part of the prefab Eithan (the weapon location) and use it in the my Player.cs script to Instantiate the weapon. I created a parameter in the script for the hand: [SerializeField] GameObject weaponSocket; and I tried to Instantiate the weapon like this like this: Instantiate(weaponPrefab, weaponSocket.Transform);, but I just cant drag the hand to the parameter.

Anyone knows how to do this correctly?

Thank you!

Images: Player script: https://imgur.com/RcvKeXN Trying to drag the left hand to the parameter (indicated by red arrows): https://imgur.com/RB63c9d

• Try changing it to [SerializeField] private Transform weaponSocket; Let me know if it works for you? Jul 2 '20 at 6:56
• didnt work, same thing happens
– roni
Jul 2 '20 at 7:33
• In your screenshot, it looks like you've selected your player prefab in the Assets folder, then tried to drag the hand from the instance in your open scene into its inspector. This will not work because a prefab cannot reference a scene object. You should select the Player instance in your scene, then try it on the instance. Then you can apply that change back to the prefab in your assets folder by applying the override. Jul 2 '20 at 11:01

What you can do is to use the method FindGameObjectsWithTag. Add a special tag to your hand and use this:

GameObject hand = FindGameObjectsWithTag("HandTag")[0];


Here is the documentation: https://docs.unity3d.com/ScriptReference/GameObject.FindGameObjectsWithTag.html

• Keep in mind that Find does a string comparison with every child of the game object, which can be quite slow for more complex ones. So it should be voided if possible. And if you have to use it (usually you don't) you should cache the result. Jul 2 '20 at 7:07
• Yes clearly, but his script will only use it one time I think. So it won't be time consuming. But it surely exists a better idea Jul 2 '20 at 7:09
• Hey, just tried it, it works for EthanBody or hips, but for some reason it returns null for the hand
– roni
Jul 2 '20 at 7:32
• Have you write the correct name? Jul 2 '20 at 7:37
• yep.. copy paste :)
– roni
Jul 2 '20 at 7:39