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.

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?

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

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

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

Why this doesnt work:

  1. What is created first? Controller or Character?

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.

Both of the screenshot were taken in the Controller

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.

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?

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.