Announcement

Collapse
No announcement yet.

Accessed None trying to read property in my Character Component... Tried IsValid

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Accessed None trying to read property in my Character Component... Tried IsValid

    Hi, I created a custom component that I added to the third person character and everything works how it should but I'm getting errors; "Accessed None trying to read property PlayerInventoryComponent" Obviously I tried using IsValid and that gets rid of the error but then nothing works lol. I'm checking if the PlayerInventoryComponent is valid.

    I have some questions,

    1) What loads or initializes first? The ThirdPersonCharacter or the Component/s attached to it? Because both have Begin Play Events.

    2) Why wouldn't my Component be valid? it's attached to my character... what am I missing.

    3) How do you initialize or set a component? Shouldn't this happen automatically when the Character is spawned?


    My game starts, then I press a key/button and check if my component is valid or not, no matter what it is always invalid, so frustrating lol I even tried delays and still nothing.

    Anyone have some insight?



    EDIT: found a work around but doubt it's right, now it works how it should and is now valid when checking, now I wonder if I have 2 PlayerInventoryComponents loaded hahaha...


    UPDATE: Problem Solved! Turns out it was some engine bug or corruption issue, what I did was remove the PlayerInventoryComponent from my ThirdPersonCharacter and then re added it, re-compiled all the blueprints that threw errors and now it works.

    Click image for larger version  Name:	fix.jpg Views:	1 Size:	136.4 KB ID:	1579662
    Last edited by Cipher5; 02-02-2019, 09:11 AM.

    #2
    Hiya,

    I generally place my components eg; inventory, stamina, HUD_Manager, etc etc etc in my player controller class, with that in mind I hope this helps:

    Q1, Im not 100% but I would think the host class or player character and its components are almost initialized together much like a single script. but then again...
    Anyway, I have not had many issues around components not being valid. Your thinking is right here, you are trying to set or call on a component before it is ready.
    Most times when this happens just add a small delay say 0.5, generally that should solve the issue. If it does then you could try lowering the delay as far as you feel comfortable.

    Q2, as above, from what you are saying it sounds like possibly things are loading and the component isnt ready to be called on yet.

    Q3, Whenever you initialize a component generally its to set a reference of your player controller, character, or HUD etc etc within the component itself to prevent any unnecessary casting.
    Or to preload items/cheat items into the inventory etc etc etc.

    For example: In my player controller, on Begin Play: I would get all components by class, loop through all of them and call event Initialize, sending to each of them the Player Controller and any other needed reference.
    But yea from what I understand you to be saying it sounds like you should try and put a small delay somewhere after Begin Play in your character, but before the Inventory Component call.

    *In the picture above, you are adding a second inventory component to the character, you dont need to do that as you have it in the components list already, and you can just drag that variable straight over to wherever you need it. anyway lmk how you get on. Cheers.
    Last edited by Neira; 02-02-2019, 01:37 AM.

    Comment


      #3
      Thanks for your help!

      Problem is now Solved, Turns out it was some engine bug or corruption issue ,etc., what I did was remove the PlayerInventoryComponent from my ThirdPersonCharacter and then re-added it, and re-compiled all the blueprints that threw errors and now it works.

      Because you made me believe I was going about it the right way I figured it had to be something engine related, or my hard drive took a dump, etc. I have had this component in my project since 4.16 I think so chances from all the engine updates something got messed up, well that's obvious now lol thanks again buddy

      Comment

      Working...
      X