Thanks for watching 🙂 I'm doing my best to help others but not all I do is for free. In my opinion everyone should get compensated if they do a good job 👍
I love your video, you don't even know how much this video helped me, you deserve more subscribers, views and likes than you have for your extreme effort. Keep going!!
Used the exact script and followed everything up to 8:00 but it won't highlight a Lantern or pillow I set as 'pickable'. Not sure what I'm doing wrong because there's no errors in the scripts and I even assigned the Highlight Script to those models.
If it doesn't highlight the objects you could check 2 things. If you can pick up the object I would check if the material has its emission parameter set - since it makes the object glow. If you can't pick up the object it means that our raycast is not detecting the object. In this case the easiest thing is to debug your code or simply "Debug.log" if something is detected by the raycast or not. It might be too short or just blocked by another object.
You could have a separate script like a "socket" where you drop the object and if it is colliding with the socket it is auto attached in the correct spot.
Thanks! All you need is instead of action start a coroutine (maybe show a progress bar) and do the action after the time is up. The only additional thing would be to add a *released* action on that button to break from the coroutine if the player let's go of the button too soon.
I tried this but I keep getting this error and I'm not sure what I missed Assets/RaycastPickupDetection.cs(30,35): error CS0246: The type or namespace name 'Highlight' could not be found (are you missing a using directive or an assembly reference?)
We don't put this script in a separate namespace. It might be an error with the Highlight.cs script. Do check if you don't see any compilation error / is the script names the same as you type it. The most often issue is misspeling the name or an error in the script that prevents it from being compiled. Less often you actually have to add at the tom "using CustomNamespace". I hope it helps!
Because we are using Kinematic RB for the item if I am not mistaken. If you make the item to have a Dynamic RB the movement will be jagged but any collision between it and wall will be detected. It is the same problem as you can see in VR games. There is no one simple solution for it. The easiest one is using a dynamic Rigidbody to prevent collision. The most "precise" one is using kinematic RB and coding your own collision reaction - so for example if player tries to push object too far into the wall the Player drops the object (the object stays on the correct side of the wall). Again there are many others so you would have to do a bit of testing / research to find out what works best for you.
@@SunnyValleyStudio Thanks for the answer. Yea i would have hoped that this mechanic was the same as we see in example Portal. Not having any success implementing is so far sadly.
That is kind of strange. Check the code for any place where we are modifying the scale. It might also happen if you are parenting the object instantiated to some parent object.
Hello, I learned a lot... Thank you. I just have a question. How can I put, for example, on the PickUpSlot a maximum of X number of itemHand I can grab and then using Mouse wheel to change into them? :D
I'm not quite sure what you mean by that. Usually you just need to write a bit more code to extend the current functionality - like when you know what is selected you can listen to scroll wheel and change some parameter before you press pick up key.
Hello. As always very good video. Can you, please, tell us the name of the tool you have on Visual Studio that try to autocomplete the code lines? Thanks.
Hey there I love thr video! Is there any way to put an item to a fixed place? Example: I pick up a vhs tape in one room, and want to put it into a vhs player in the other room.
Hey! The simplest solution to this would be to leave the default "drop" logic and add a trigger collider to the vhsplayer. The vhsplayer could check continuously (or using events to handle swapping items when in range of the collider) in case the player gets close "is the item player is holding a VHS tape?" if so maybe show "press E to use" or if you want to use the same button press add a bool flag that will ignore the default drop logic and instead use some custom logic in vhsplayer update() that check "if drop button was pressed remove the VHS tape from player and play the video"
In First Person you can very easily direct a simple Ray at the object. in 3rd person I would use something like SphereCast / Sphere trigger collider to detect object since it might be much harder for the players to point at the object. I mean you can use this method yes but for the sake of having a great experience I would modify the detection to be more forgiving rather than asking you to point exactly at the object. Still it should work.
Hello I have small problem I did everything as you did except I used “old input system” and it doesnt work I mean it pickups the items but it doesnt drop them I put debug log on it and it doesnt even print that do you know what could be problem. Thanks
Hey! It should not matter. The logic is *if I am holding something the drop button will drop it* I suspect that you may have a bug in your logic. Check your script again mine (github link) or verify if you ex can debug.log when you press the drop button using your setup. Thos kind of bugs are often caused by us messing up the logic behind reading the input and not the code that we write later. I hope that helps!
@@SunnyValleyStudio I checked if I press Q for drop before I pickup anything it will Debug Log the text but if I pickup and then press it will not work I can send you code
Hi, great video. It definitely helped me with my project. I just have a question. How do I increase the length of the hitRange? I tried increasing the value to 1000 but doesnt change.
If you are asking for the Raycast code insider Player.cs you have to multiply " forward * 1000" since Physics.Raycast takes the origin point and the direction so we need to inscreas the length of the direction vector. I hope it helps!
Hey! This tutorial will give you an idea of how to structure your code base behind a pickup system but obviously the example is in 3d. For a 2d game you would basically need to modify the Raycast logic to use *Physics2d.Raycast* I show how to implement a simple 2d pickup logic in my inventory tutorial (in one of the last parts). You can watch only that part or the whole inventory setup if you are interested. Here is the link to part 18 where I show how to pick up items ua-cam.com/video/ysUb6u08uMo/v-deo.html
hey nice video! but i get a lot of errors like: Assets\Scripts\Player.cs(76,25): error CS0246: The type or namespace name 'InputAction' could not be found (are you missing a using directive or an assembly reference?) or: Assets\Scripts\Player.cs(41,12): error CS0246: The type or namespace name 'InputActionReference' could not be found (are you missing a using directive or an assembly reference?) can you help me pls?
and i think its because of this: Assets\Scripts\Player.cs(5,19): error CS0234: The type or namespace name 'InputSystem' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)
Hey! I think you are missing the new input system package and that is why you have all those errors. Installing it should help! Here is how docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Installation.html If you have used my starter package it should be included. Sorry if it wasn't!
Inside the Player script we do "inHandItem.transform.SetParent(pickUpParent.transform, pickableItem.KeepWorldPosition);" which portents the item to our Player character. We also set the items RigidBody to be kinematic inside PickableIte.cs. That is what makes the item follow the player github.com/SunnyValleyStudio/Unity-simple-Pick-Up-system/blob/main/Player.cs#L78
NullReferenceException: Object reference not set to an instance of an object Player.Start () (at Assets/Scripts/HelperScripts/Player.cs:45) does not work as it always gives this error and has the new input system and the version of Unity is 2021.3.16f1 and Input System 1.4.4
NullRef exception means that something is null. At line 45 of Player script we have *useInput* reference. It is assigned in the inspector of the Player.cs ([SerializeField] private InputActionReference interactionInput, dropInput, useInput;) Are you sure that you have assigned it there? I think I explain it at 11:35
What do you mean exactly? If you want to have a 3rd person camera with a character animated with Mixamo you would use something like SphereCast or OverlapSphere to detect the object to interact with instead of raycasting from the camera (unless you have an isometric camera and its more convenient ). You would just play the "pick up" animation and use animation events to trigger the pickup logic. If you mean FPS + a 3d character the solution would be the same as above.
Maybe for some reason the DROP action input is not assigned / is not set correctly in the Player.cs script or in the Input Actions asset where we have assigned keyboard keys to the Drop action?
Building a game is different depending on a platform and the project. Your game might work well in the editor but might require modifications when creating a build. That is why it is useful to try to build the game as soon as the first prototype to avoid major changes.
@@SunnyValleyStudio No i mean the link dont work, i press the button to download from the drive and dont does nothing, allready tried it with other browser
Nice video where you can understand all and learn how is it works. Very helpful.
Thanks 👍
Part 2 -> ua-cam.com/video/t-WkP_UyrgU/v-deo.html
XD
u sound like a good man. many thanks for this and giving us for free.
Thanks for watching 🙂 I'm doing my best to help others but not all I do is for free. In my opinion everyone should get compensated if they do a good job 👍
Best video for learning Pickup mechanism...I found many videos but this one is the perfect... 😊😊😊
Thanks for watching!
I love your video, you don't even know how much this video helped me, you deserve more subscribers, views and likes than you have for your extreme effort. Keep going!!
I'm glad that I can help you with my videos 🙂 Thanks a lot for watching! 👍
Extremely helpful tutorial, thank you!
Thanks for watching!
Thanks for good videos ☺️
Glad you like them! Thanks for watching 🙂
Used the exact script and followed everything up to 8:00 but it won't highlight a Lantern or pillow I set as 'pickable'.
Not sure what I'm doing wrong because there's no errors in the scripts and I even assigned the Highlight Script to those models.
If it doesn't highlight the objects you could check 2 things. If you can pick up the object I would check if the material has its emission parameter set - since it makes the object glow. If you can't pick up the object it means that our raycast is not detecting the object. In this case the easiest thing is to debug your code or simply "Debug.log" if something is detected by the raycast or not. It might be too short or just blocked by another object.
after learning this by combining sources. i then found this video .... MOTHER! FFFF
Hey! I'm doing my best to create tutorials about whole game mechanics. Maybe you will find some other of my series helpful 😉
I want to drop object in a a specific place in a centre of the place is like a lab device, how can I do that...
You could have a separate script like a "socket" where you drop the object and if it is colliding with the socket it is auto attached in the correct spot.
@@SunnyValleyStudioCan you make short video on this..or script..
Thanks for great video, what would you to instead of press to pick up, hold to pick up
Thanks!
All you need is instead of action start a coroutine (maybe show a progress bar) and do the action after the time is up.
The only additional thing would be to add a *released* action on that button to break from the coroutine if the player let's go of the button too soon.
I tried this but I keep getting this error and I'm not sure what I missed Assets/RaycastPickupDetection.cs(30,35): error CS0246: The type or namespace name 'Highlight' could not be found (are you missing a using directive or an assembly reference?)
We don't put this script in a separate namespace. It might be an error with the Highlight.cs script. Do check if you don't see any compilation error / is the script names the same as you type it. The most often issue is misspeling the name or an error in the script that prevents it from being compiled. Less often you actually have to add at the tom "using CustomNamespace". I hope it helps!
Any idea why me item object can go through walls when im holding it?
Because we are using Kinematic RB for the item if I am not mistaken. If you make the item to have a Dynamic RB the movement will be jagged but any collision between it and wall will be detected. It is the same problem as you can see in VR games. There is no one simple solution for it. The easiest one is using a dynamic Rigidbody to prevent collision. The most "precise" one is using kinematic RB and coding your own collision reaction - so for example if player tries to push object too far into the wall the Player drops the object (the object stays on the correct side of the wall). Again there are many others so you would have to do a bit of testing / research to find out what works best for you.
@@SunnyValleyStudio Thanks for the answer. Yea i would have hoped that this mechanic was the same as we see in example Portal. Not having any success implementing is so far sadly.
Sir, I have a problem, when I droup object the size of object getting small..
That is kind of strange. Check the code for any place where we are modifying the scale. It might also happen if you are parenting the object instantiated to some parent object.
I want to drop object in a specific place in a centre of the place is like a lab device, how can I do that...
@@SunnyValleyStudioThis fixed..
I have one more questions..
Specific place I want to drop the object in centre how can do that..
Hello, I learned a lot... Thank you. I just have a question. How can I put, for example, on the PickUpSlot a maximum of X number of itemHand I can grab and then using Mouse wheel to change into them? :D
I'm not quite sure what you mean by that. Usually you just need to write a bit more code to extend the current functionality - like when you know what is selected you can listen to scroll wheel and change some parameter before you press pick up key.
Is the Unity OOP course going to be available on Udemy?
Yeah it is. Here is a link www.udemy.com/course/oop-for-unity-devs/?couponCode=30_OFF
Hello. As always very good video. Can you, please, tell us the name of the tool you have on Visual Studio that try to autocomplete the code lines? Thanks.
Hey!
It's Visual Studio 2022 with the latest update.
press tab twice
thanky
Thank for watching 👍
Hey there I love thr video! Is there any way to put an item to a fixed place? Example: I pick up a vhs tape in one room, and want to put it into a vhs player in the other room.
Hey!
The simplest solution to this would be to leave the default "drop" logic and add a trigger collider to the vhsplayer. The vhsplayer could check continuously (or using events to handle swapping items when in range of the collider) in case the player gets close "is the item player is holding a VHS tape?" if so maybe show "press E to use" or if you want to use the same button press add a bool flag that will ignore the default drop logic and instead use some custom logic in vhsplayer update() that check "if drop button was pressed remove the VHS tape from player and play the video"
Is this working for third person player? I'm planning to make the player pickup the item that's in front of him
In First Person you can very easily direct a simple Ray at the object. in 3rd person I would use something like SphereCast / Sphere trigger collider to detect object since it might be much harder for the players to point at the object.
I mean you can use this method yes but for the sake of having a great experience I would modify the detection to be more forgiving rather than asking you to point exactly at the object. Still it should work.
Hello I have small problem I did everything as you did except I used “old input system” and it doesnt work I mean it pickups the items but it doesnt drop them I put debug log on it and it doesnt even print that do you know what could be problem. Thanks
Hey! It should not matter. The logic is *if I am holding something the drop button will drop it*
I suspect that you may have a bug in your logic. Check your script again mine (github link) or verify if you ex can debug.log when you press the drop button using your setup. Thos kind of bugs are often caused by us messing up the logic behind reading the input and not the code that we write later.
I hope that helps!
@@SunnyValleyStudio I checked if I press Q for drop before I pickup anything it will Debug Log the text but if I pickup and then press it will not work I can send you code
Same thing is happening to me
For me it was because the if(inHandItem != null) was too high in my update script. So if I had an item in my hands it would skip the rest of my update
Hi, great video. It definitely helped me with my project. I just have a question. How do I increase the length of the hitRange? I tried increasing the value to 1000 but doesnt change.
If you are asking for the Raycast code insider Player.cs you have to multiply " forward * 1000" since Physics.Raycast takes the origin point and the direction so we need to inscreas the length of the direction vector.
I hope it helps!
@@SunnyValleyStudio That was exactly what i needed, thanks
I havent watched this series yet and just want to know if this applies to 2d before i do? thanks.
Hey!
This tutorial will give you an idea of how to structure your code base behind a pickup system but obviously the example is in 3d. For a 2d game you would basically need to modify the Raycast logic to use *Physics2d.Raycast*
I show how to implement a simple 2d pickup logic in my inventory tutorial (in one of the last parts). You can watch only that part or the whole inventory setup if you are interested. Here is the link to part 18 where I show how to pick up items ua-cam.com/video/ysUb6u08uMo/v-deo.html
hey nice video! but i get a lot of errors like: Assets\Scripts\Player.cs(76,25): error CS0246: The type or namespace name 'InputAction' could not be found (are you missing a using directive or an assembly reference?)
or: Assets\Scripts\Player.cs(41,12): error CS0246: The type or namespace name 'InputActionReference' could not be found (are you missing a using directive or an assembly reference?)
can you help me pls?
and i think its because of this: Assets\Scripts\Player.cs(5,19): error CS0234: The type or namespace name 'InputSystem' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)
Hey!
I think you are missing the new input system package and that is why you have all those errors. Installing it should help!
Here is how docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Installation.html
If you have used my starter package it should be included. Sorry if it wasn't!
@@SunnyValleyStudio oh ok thx but now if i Start unity there is a Tab saying restart unity because native input or something
Why does the item hang in place and not move behind the character?
Inside the Player script we do "inHandItem.transform.SetParent(pickUpParent.transform, pickableItem.KeepWorldPosition);" which portents the item to our Player character. We also set the items RigidBody to be kinematic inside PickableIte.cs. That is what makes the item follow the player github.com/SunnyValleyStudio/Unity-simple-Pick-Up-system/blob/main/Player.cs#L78
NullReferenceException: Object reference not set to an instance of an object
Player.Start () (at Assets/Scripts/HelperScripts/Player.cs:45) does not work as it always gives this error and has the new input system and the version of Unity is 2021.3.16f1 and Input System 1.4.4
NullRef exception means that something is null. At line 45 of Player script we have *useInput* reference. It is assigned in the inspector of the Player.cs ([SerializeField] private InputActionReference interactionInput, dropInput, useInput;)
Are you sure that you have assigned it there? I think I explain it at 11:35
@@SunnyValleyStudio Thank you very much, that’s what I needed
Hi how can it be possible to do it with a mixamo character
What do you mean exactly? If you want to have a 3rd person camera with a character animated with Mixamo you would use something like SphereCast or OverlapSphere to detect the object to interact with instead of raycasting from the camera (unless you have an isometric camera and its more convenient ). You would just play the "pick up" animation and use animation events to trigger the pickup logic.
If you mean FPS + a 3d character the solution would be the same as above.
It won't drop down the item, but I have the exact same code :(
Maybe for some reason the DROP action input is not assigned / is not set correctly in the Player.cs script or in the Input Actions asset where we have assigned keyboard keys to the Drop action?
@@SunnyValleyStudio I did check it multiple times and it seems fine. But it's like the buttons till won't work :( it's okay tho
the build of the game does not work backlight items
Building a game is different depending on a platform and the project. Your game might work well in the editor but might require modifications when creating a build. That is why it is useful to try to build the game as soon as the first prototype to avoid major changes.
the download of the starter project dont work
Hey! I have just downloaded the project and opened it in Unity 2021.3.1f1 and everything works great!
@@SunnyValleyStudio No i mean the link dont work, i press the button to download from the drive and dont does nothing, allready tried it with other browser
You have link another vdo for pick item for Mobile game like granny if you have then share me i am still waiting