Download

Destroy a box by hit it

Hello!

Can anyone tell me whats wrong with this code. I have not done a end overlap on it. I would that if the character goes in the collission box and press E. The box will be vanish.

This is a UE4 question. You posted in the UE3 section of the forum. You’ll probably get a better answer if you ask elsewhere. Good luck.

Currently it’s not working because regular actors do not process input, not by default. It can be enabled in the Class Defaults but it’s not recommended:

image

It will really muddy up the water and make it a royal pain in the neck to handle input. Avoid it unless you need to implement some very specific mechanics.

Lets say you have 10 boxes, when you press E, ALL boxes will execute that script… Do you need that or do you need to destroy the box the player touched?


Consider the following instead:

Such interaction should be scripted in the player (or player controller). It’s the player who should be doing the checking and key-pressing. Otherwise you’ll end up implementing the same script in every object that needs interacting with…

  • this is my player with a collision sphere:

  • when they press 1, we check whether the sphere overlaps any myBoxes and Destroys one.

Is this roughly what you’re after: