Why getting player pawn actor component doesn't work if function called from blueprint function library?

Here is a curiosity. For the sake of convenience, I put a function in a blueprint function library that gets the player pawn, gets an attached actor component, and returns a member variable of that component.

But that function returns nothing when I use it, but if I put the same nodes into a blueprints event graph directly, it does work.

In the function library:

I guess it must have something to do with the world context? I am not sure what that means, but for example, I use similar functions for getting other actor references and it works fine.

I believe it has to do with the world context. You can connect it as a function input, and from your player, “get a reference to self” if called from your player BP or “get player character” if called from somewhere else. That should work.

1 Like

i will give that a shot - makes sense.

but one other thing, I should have posted this in original:

this works no problem. It is fundamentally the same thing, right? Only difference is that a component is not involved.

actually, ya know what. I think perhaps that variable is out of scope? that is probably the issue.

1 Like

yeah it was the variable being out of scope I believe, because this works:


Perhaps, I would also add the actor as input in the function and fit get a reference to self or get player pawn as explained before.

Glad to know you sorted things out. Keep up the good work.

1 Like