Forum begins after the advertisement:
[Part 4] Cant pick up Items.
Home › Forums › Video Game Tutorial Series › Creating an Underwater Survival Game in Unity › [Part 4] Cant pick up Items.
- This topic has 9 replies, 2 voices, and was last updated 3 months, 1 week ago by Poisonoaks Studio.
-
AuthorPosts
-
August 11, 2024 at 4:46 pm #15560::
So, ive done the entire code, theres no errors until I play it and when I try to pick up an item it gives me
NullReferenceException: Object reference not set to an instance of an object
Is this something fixed in the next episode? I just don’t want to move on without knowing for sure.Edit: I fixed the original issue! But now it gives me that same error whenever I try to transfer between storage and inventory
NullReferenceException: Object reference not set to an instance of an object ExtendedStandaloneInputModule.GetPointerEventData (System.Int32 pointerId) (at Assets/Scripts/Inventory/ExtendedStandaloneInputModule.cs:16) InventorySystem.Update () (at Assets/Scripts/Inventory/InventorySystem.cs:48)
August 11, 2024 at 5:25 pm #15561::Hi Poisonoaks, if you run into a null reference again, do post the script and highlight the line that has the issue, so that I can fix the issue for you.
You can also check this video to see how to fix these issues.
August 12, 2024 at 4:24 am #15563::Yeah, I’m still not sure whats going wrong. Its bringing me to two different sets of code and I dont see an error in either of them
PointerEventData hoveredObj = ExtendedStandaloneInputModule.GetPointerEventData();
This is the exact line for the one in InventorySystem._instance.GetPointerData(pointerId, out eventData, true);
and this is ExtendedStandaloneInputModuleAugust 12, 2024 at 5:06 am #15564::Heres the photo of what it exactly takes me too with the entire script pulled up
August 12, 2024 at 10:49 am #15567August 12, 2024 at 2:25 pm #15571::using UnityEngine.EventSystems; public class ExtendedStandaloneInputModule : StandaloneInputModule { private static ExtendedStandaloneInputModule _instance; protected override void Awake() { base.Awake(); _instance = this; } public static PointerEventData GetPointerEventData(int pointerId = -1) { PointerEventData eventData; _instance.GetPointerData(pointerId, out eventData, true); return eventData; } }
August 12, 2024 at 2:26 pm #15572::If it means anything, the sorting system is all weird. Im not sure whats causing it but it theres spacing inbetween the items, and im not sure whats causing it or who to fix it, but I can work around it and it doesn’t bother me. Just if you think it has any correlation
August 12, 2024 at 10:05 pm #15575::I think you need to add an Event System to your Canvas (if you don’t have one already). Then, check if it has a
StandaloneInputModule
. If it has one, you will need to replace it withExtendedStandaloneInputModule
.In your code, this line is giving a null reference exception:
public static PointerEventData GetPointerEventData(int pointerId = -1) { PointerEventData eventData; _instance.GetPointerData(pointerId, out eventData, true); return eventData; }
It is likely because
_instance
is null. It will only be null if you have no existing copies of theExtendedStandaloneInputModule
in your Scene, because theAwake()
method will populate it.Hope this helps!
August 12, 2024 at 10:07 pm #15576::As to whether this is fixed in the next episode, I’m not very sure. I haven’t looked at this project in too much detail, and the Grid system has been updated since we made this tutorial, so parts of the guide are different now.
If you can let me know about this when you move on to the next part, that will be great!
August 13, 2024 at 2:57 am #15578::Yup… that did it, I feel a little stupid. But thanks anyway! It didn’t fix the inventory grid and the new grid system just gives me a bunch of errors. its weird, but like I said, i can fix it. I can maybe find a way to make it scrollable. Thank you so much for making this headache go away.
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: