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 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.
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.
â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.
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.