Download

Applying actions only to certain objects

Bit of a newbie question here. I am developing a VR experience on Quest. I have an electric screwdriver which actives on a button press from the VR controller. However, currently the button press activates the screwdriver whether the screwdriver (blueprint) is held of not. Obviously I need it to only happen when the screwdriver is picked up with the ‘grabcomponent’ command.

I have successfully created a variable attached to the grab controller logic, so it knows when any object is picked up or not, but I need to link this variable specifically to instances where only the screwdriver is picked up. I just need pointing in the right direction to achieve this?

Any help would be appreciated. I tried getting actors of class ‘screwdriver blueprint’ before setting the is it held variable, but this didn’t seem to work, so not sure what next to try?

Straightforward approach is to create an event in the parent class, then override that event in the child.

Parent class [Button Event] → child class screwdriver [button event override]

1 Like

Many thanks for the response, could you possibly add a bit more context? As I don’t fully understand what you mean…

Currently my button event is in the VR Pawn, the button triggers a rotation of the screwdrivers chuck and plays a sound, and them stops the rotation and plays another sound on release.

Are you suggesting I create a different event in the VR Pawn with some kind of override variable which I access from the screwdriver blueprint?, or what type of event would this be?

I might add, that as far as I am aware, the screwdriver blueprint is not the child of the VR Pawn? But I could be wrong about this?!

I’ve managed to get something working; in the end I created a variable for when the screwdriver is picked up, to say I am a screwdriver, then I did two checks on the button event to ask, is an object is picked up? and if so it is is it a screwdriver?

Maybe not the best way of doing things, but it seems to work!

Thanks RevOverDrive for your help all the same

No, I’m say that you should have an Actor Class as parent and then create child classes of it for items having similar properties.

e.g.
Weapon class (parent) … all firing, reloading, toggling fire mode logic is in the parent.
Wep_AK47 would be a child class of Weapon. I don’t have to rewrite firing, reloading, toggling etc. It’s inherited from the parent.

The twist … Say I have three firing modes in the parent class. Auto, Burst, Semi-Auto. The AK might only need two. So in the AK class there will be an event “Burst Fire”. I’ll overwrite that event…pipe a branch node to it. Now no matter what anyone does (e.g. cheats) that weapon will never burst fire.

Same for a screwdriver, hammer, shovel. Parent has one event with no code logic applied to it. Say “Action”. In each of these classes I would Override the parent “Action” event and code up the specific logic for the child item.

If you need an example I’ll script one up real quick.

I have it working but I’d like to understand more what you mean…

I think I follow. So in this case, the parent class might be ‘tool’ BP? then the child will be ‘screwdriver’ BP or ‘spanner’ BP etc? Are the children derived from the Parent of tool BP?

Would the VR Pawn then reference the ‘tool’ action and the override reside within the specific tool, i.e. screwdriver/spanner?

Yup that’s pretty much it.

BP_Tool → BP_Screwdriver (Tool)
“Action event” in Tool class → Overridden in screwdriver

If setup correctly you only need to have a BP_Tool obj reference to store any tool. So no down casting needed to use BP_screwdriver. just a simple BP_Tool → Action event call.

Thanks

I would create a socket on the controller and when you grab the screw driver parent the screw driver to the socket. Then when you press you interaction button, check if the child of the socket is = to the screwdriver, if it is then cast to the screw driver (or bp interface to it) to run the code on the screwdriver bp. Then when you let go of the screwdriver, I parent it from the socket.

A lot easier to simply have an actor object reference (Tool) then do an is valid on it.

If All tools derive from BP_Tool, then you can have a single var “Current Tool”. Simply set and unset.

input → Is valid (current tool] → Tool Action Event