How can I get a player number/ the controlling player in another BP

Sorry if the title is misleading, I’m not exactly sure how to word this.

Essentially what I’m trying to do, it pick up a weapon or other object. Now picking it up works just fine, but only for the first player. So when I interact with it and try and pick it up with he second player, it will put it in player 1’s hands.

I know why it’s doing this (Because it gets player index 0), But I can’t figure out exactly how to fix this???
Also, when I spawn the characters(Which is being done through the characterBP) I AM giving them an PlayerIndexCacheNumber.(Which I know for a fact is working…) (If that helps you explain a fix to this)

Lastly, I’m trying to do it* without* casting if that is possible? BUT if that’s all you know how to help me with, it’s definitely start because I still know little about it!
Can I do it through interfaces? That’s what I’ve done so far for shooting, singleplayer pickup, ect.

The issue is obviously in the Weapon BP because nothing is in the player index.
Weapon BP


Character BP

If its any help, I would restructure this a bit and create a custom Player Controller. The Input for the Pickup you get in your Player Controller, than you use the node, “Get Controlled Pawn” and cast it to your Custom Pawn/Character class and than either call a custom event or interface event.

Than the checking if it is a weapon I don’t really get. Since it is on the Weapon it self you essentially only want to say that it should trigger the Weapon pickup specific functionality within your Character? And what I understand, Looking at What is essentially a Actor Variable so you can us it in different ways?

Why not trace for the objects in your environment, feed the Looking at What? Variable and than cast it to those Actors and than trigger if necessary some events on the actor or pawn.

Hope it helps, otherwise let me know. Would be nice to know, what speaks against casting in your desired framework, and what exacly Looking at What, and if my assumption is right.

Best

Sorry, for the lack of explanation. I’m sure you may be able to tell I’m pretty new to most of this.

Right now I’ve been getting most of this set up from a sort of tutorial somebody else posted(About halfway down)

Also I just learned about the interfaces through unreal communication tutorial. SO I’m still figuring them out.

Right now I have it so when you press “E” a ray is actually cast from the character and it “searches” for another object that has the “On Interact” event.


When you interact with a weapon, it equips it, assuming use you have anything already equipped. I see now though that my “LookingAtWhat” Variable can only get a weapon right now which doesn’t make much sense.

I’m not entirely sure though how to go about creating a custom player controller though and how to use it in this situation.
Here is my character spawning, if it helps. Just and Enumeration with 1 or 2 players as an input. (Always creates the first player)


And I just didn’t want casting because it seems like it would limit me in ways I feel like interfaces can do similar things across multiple actors, but then again I know very little about casting. :expressionless:

Nevermind! Got it all figured out without even needing player pawn,controller, ect.

All I did was add an input for the Interface Interaction Function.
Just calls itself to send it to where ever it is being called, then plugged it in. (If any of that makes sense)

I’m sure it’ll all run into errors soon enough… :stuck_out_tongue:

Weapon/Object


Character