Forum begins after the advertisement:


[Part 4] Cant pick up Items.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #15560
    Poisonoaks Studio
    Participant
    Helpful?
    Up
    0
    ::

    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)
    #15561
    Terence
    Keymaster
    Helpful?
    Up
    0
    ::

    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.

    #15563
    Poisonoaks Studio
    Participant
    Helpful?
    Up
    0
    ::

    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 ExtendedStandaloneInputModule

    #15564
    Poisonoaks Studio
    Participant
    Helpful?
    Up
    0
    ::

    Heres the photo of what it exactly takes me too with the entire script pulled up

    View post on imgur.com

    #15567
    Terence
    Keymaster
    Helpful?
    Up
    0
    ::

    Can you post your whole ExtendedStandaloneInputModule script here?

    #15571
    Poisonoaks Studio
    Participant
    Helpful?
    Up
    0
    ::
    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;
        }
    }
    
    #15572
    Poisonoaks Studio
    Participant
    Helpful?
    Up
    0
    ::

    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

    #15575
    Terence
    Keymaster
    Helpful?
    Up
    0
    ::

    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 with ExtendedStandaloneInputModule.

    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 the ExtendedStandaloneInputModule in your Scene, because the Awake() method will populate it.

    Hope this helps!

    #15576
    Terence
    Keymaster
    Helpful?
    Up
    0
    ::

    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!

    #15578
    Poisonoaks Studio
    Participant
    Helpful?
    Up
    0
    ::

    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.

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: