Announcement

Collapse
No announcement yet.

Update function doesnt work, why?

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

    Update function doesnt work, why?

    Hey guys,

    I have a update function, which should update a variable on widget, but it doesnt work. I call the function in the LevelBlueprint just for testing.

    Click image for larger version

Name:	Dollar.PNG
Views:	1
Size:	61.1 KB
ID:	1213326

    Error I get:
    Error Blueprint Runtime Error: Accessed None trying to read property Inventory from function: 'UpdateDollar' from node: SetText (Text) in graph: UpdateDollar in object: ThirdPersonPlayerController with description: Accessed None trying to read property Inventory

    Where is the mistake, I made?

    #2
    Show [post a screen shot of] the nodes that sets the inventory reference.

    Comment


      #3
      In the third person character I spawn the inventory on EventBeginPlay and the return value I set to the InventoryRef in my Char Blueprint. In my Controller on EventBeginPlay I cast to my Char get the Ref and set it to the ref in my Controller. Like this it doesnt work. It works when I directly cast to my char in the function and get the ref. The same Error appears.

      The update function I call in my Inventory on EventBeginPlay (When in my Char the Inventory is spawned.

      But when I call the function on EventBeginPlay in my Levelblueprint it works hm

      Comment


        #4
        EDIT: hm... a Delay of 0.000001 helped. Now everything is working fine.

        EDIT: Sorry for editing in another post. on my phone I dont see the edit function. I have two more question: 1. Cant I just Cast to my Char in the Controller and set the InventoryRef of my Char to the InventoryRef of my Controller and then use the InventoryRef without casting to my Char all the time in the function? It looks like this now

        Click image for larger version

Name:	Dollar1.PNG
Views:	1
Size:	95.7 KB
ID:	1124918

        Why this doesnt work:

        Click image for larger version

Name:	Dollar2.PNG
Views:	1
Size:	31.2 KB
ID:	1124919

        2. What is created first? Controller or Character?
        Last edited by Glypton; 03-19-2017, 11:56 AM.

        Comment


          #5
          The reason you're getting the error in your controller, is because on the controllers begin play, the pawn does not yet possess. You need to use a delay. [I advice not the delay node, but set timer by event].
          I still don't get how the Level Blueprint sets the inventory reference, but the point is that it is not set correctly, which is why the "accessed none" error.

          Comment


            #6
            Both of the screenshot were taken in the Controller

            Comment


              #7
              On begin play of the controller, it does not yet possess any player, so "get player character" is null. They may both be created, placed in the level or whatever, but the controller does not possess anything.

              To answer your first question, yes you can. I assume that the inventory is an actor or actor component, so the variable inside the controller would point to that reference.

              Comment


                #8
                Thank you! Everything work as it should. Last question: You said I should use a Set Timer by Event instead of Delays? And what should I connect to the custom event? If I just connect the Casting Part to it, then isnt it like a Delay?

                Comment


                  #9
                  Well, the delay node for this kind of thing is fine. There was some reason to not use it for bigger setups I think, but I can't remember what it was.
                  But you use the "set timer by event" by dragging the red square onto the red square of a custom event.

                  Comment

                  Working...
                  X