how do you set a specific collision box to be interacted?

so currently i have this script that lets you enter and exit a car but i want to limit it to only use one collision box that way i can add other collision boxes to do other things when entered. hopefully that makes sense

this is the part where you interact

i want it to only work with the big box and not the small one as that would then be used to open the trunk
image

You can right click on the box in the component list, and get an event to react to just that box

image

awesome but how would i get the begin overlap from the first person character to fix the script? i cant seem to cast and get it

This approach of treating the action “globally” like you do can grow to become unmanageable. It would make more sense to let those components “talk” to your player directly via some API/Interface when OnComponentBeginOverlap happend. That way it is more modular and you can allow same components to “turn on” different functionality for your player.

It is obviously more work at the beginning but definitely is worth in the long run, even more so if you want to keep expanding what the player is allowed to do.

That’s the thing that you have to implement this in the component’s event graph, not the first person’s bp event graph. First step is what @ClockworkOcean is saying, then when you have the casted BP you can call methods on your BP, but since you have the action mapped to the player, this won’t work the way you have it setup now.

That’s why when player presses the button, you should check what he can do and if “bCanEnter/ExitVehicle” is set to True, you can do that action.

Setting those variables is in competence of components which are allowed to do so.

1 Like

i think ive read what you said like 4 times, and i am having a really hard time grasping what you are saying i already use a bpi it already interfaces back and forth

I think @Ligazetom is just saying you’ve got the thing back to front.

You’re doing it so the player presses ‘use car’ and then your system looks for overlaps etc.

But maybe you need to drive ( pun intended ) the whole thing from the other end. When something overlaps with the car door, you check if it’s the player, if it is, you ask them if they want to get in.

okay so this is what i tried

it doesnt seem to do anything if im in the box and hit enter but if i remove the keypress check it enters the car when walking up to it

edit: i did realize that i can plug one input down into the enter exit key so that part is cleaned up but thats not the issue

Look, just stop and think about it.

“If you press ‘E’ you want your player to do something depending on the surroundings”. Be it Enter/Exit or Pick/Use something. You don’t want to map all of these actions to different keys because soon you’ll run out of keys. You want it to be CONTEXT SENSITIVE.

So in your player BP, you will have the ActionEvent as you already have. But instead of checking the surroundings, check the created flag (boolean variable) for this exact action, if it is allowed or not (e.g. bCanEnterCar).

Create methods (or expose it directly but this is not really good approach, because maybe you’ll want to do something else too when setting the flag in the future e.g. update interface to let player know he can do this action) to set the flag on/off.

Now open the BP of the vehicle, which has the collision component. Implement OnComponentBeginOverlap method, get the player it is overlapping with, cast it to your BP and call the method for setting the flag On.

Now your player is in STATE that is allowing him to enter vehicle ONLY when he presses the key, doesn’t have to, but he CAN.

Then when the player leaves the component volume, turn the flag off the same way.

Done. And you can do this for anything and suddenly you are able to have one key doing multiple actions, all depending on the state of the player and you can even make one collision component to turn on multiple flags on the player and it is all self contained.

1 Like

alright i give up im too stupid for this

No you’re not :slight_smile: gimme a moment…

To your original method, add this little tweak

Because, you can tag components

And that means you can check which car collision box you’re overlapping with.

All @Ligazetom was saying, is that it’s usually done the other way around. The car tells the player interaction is possible. Why bother looking at all the actors in the vicinity, when the actors can alert the player to the possibility of interaction. That’s all.

1 Like

okay i tried this

but sadly it wont let me in the car and yes i set up the tag

You’re not checking the tag

image

okay hopefully this is sufficient, it lets me in the car but it also does if i use the other box so its still ignoring the tag ?

Seems overly complicated

Print out the name of the box, check you’re getting what you think you’re getting…

i get nothing
then again i could be printing it wrong idk

Put a print node here

image

and drag the component pin into it, it will convert to ‘display name’ ( probably )

image

I’m starting to think you’re getting the car mesh itself…

okay it did grab the bounding box that i want so what would cause it to still enter the car when overlapping the other box