- Home /
Using Part of prefab as script parameter
Hey,
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
Answer by UnityedWeStand · Jul 02, 2020 at 07:14 AM
Ah, your screenshots confirm my suspicions. You are attempt to set an instance of the hand object as a parameter of the script on the root prefab of the player. This is not allowed in Unity.
What you need to do is actually open the player prefab itself. Then, in the gameobject hierarchy of the prefab, find the hand object and drag it into the script parameter.
I actually tried that, same thing happened. I cant drag it
Can you post a screenshot/video of you attempting to do this while in prefab editing mode? If it doesn't work then, that's a bug with Unity.