How to detect collision between an actor and the player character without specifying the character blueprint?

I’m setting up a game where you can switch between controlling two characters. I have a collectible actor blueprint and I want whichever character in its collision sphere to able to pick it up.

Is there a way to cast to whoever the player character is, or do I need to cast to each character separately?

I tried this but it doesn’t work…


I looked it up and a lot of the results have a castToPlayer node, which is strange cause that doesn’t show up at all for me

Just make a “master” BP class for your character and create 2 “child” blueprints with different meshes to be your two different “characters”. So on overlap just cast to the “master” character BP and it will pick up either one.

Oh you can do that? awesome. So should the parent blueprint also be a character blueprint but without the character mesh,camera…etc?

Or this.

I think it’s exactly the usecase for “GetOwningPlayerPawn” and\or “GetOwningPlayerController” nodes.

The parent would be whatever base class you use for your controlled characters. So if that is a character BP then yes, if it is a pawn BP then use pawn and make it the “parent” and create children from it. You could use the answer below as well (it is quicker) if you just need a simple “trigger” for something in your level when the player overlaps, but I think a “parent” class instead of just checking for the controlled pawn will be better for your situation since you have a “collectible” item. I assume at some point there is going to be functionality to “give” this item to the player or have it modify variables in the player class at which point you would need to “cast” to the specific controlled pawn anyway. Depends what you are trying to do. You would keep the “mesh”, “camera”, “movement” etc from the parent BP and just create variables for each component you wish to modify in the children. So if you want a new “mesh” in the parent you would have a pin off of “begin play” for example that will “get” the “mesh component” of the parent and then a node that “sets mesh”. The “mesh” you “set” to would be promoted to a variable and this would be modifiable in any child BP.

Gotcha. Thanks a lot for the help. I set it up like you said and it works. One last question, o for the character movement and other shared/inherited components, the only way to change it for separate children is to set it up with nodes? There’s no way to change the settings in the viewport without affecting all the other child blueprints?

what do you mean without affecting all other children? You set up the nodes in the parent and you can make those variables editable and then change each one in the viewport. You can set any variable to be public and editable by clicking the icon next to the variable then the little “eye” opens and it’s public and editable in the viewport

Thanks! Yup, that worked

Yup. Thanks! I just assumed that if I edited the inherited components in the viewport it will affect all the instances since it says (inherited) next to those components but I just checked and you’re right, that’s not the case. Again, thanks a lot!

Anytime man. Glad I could help!