Allowing a character to walk into and destroy destructibles?
Hey all, I'm trying to give my player some physical presence in the world. Specifically for the purpose of allowing him to walk through destructibles (colliding with and destroying them). Any idea on how I should start going about this?
If you want to do it in blueprints, select a blueprint that you wish to make destructible and open it in the Blueprint editor. Right click on the event graph and type "Event ActorBeginOverlap", then select Event ActorBeginOverlap to add the node to the graph. Right-click somewhere else and type in "Destroy Actor", then click on Destroy Actor to add it to the graph. Drag from the execution pin (the triangular one pointing to the right) on Event ActorBeginOverlap to the input pin (it looks the same, but it's on the right side) on DestroyActor.
If you want to do it in C++, create a Go to File->New C++ Class... and set the parent class to Actor. Then you can name it to DestructibleActor or something similar. Once that is done, you can open the new C++ class in your IDE (Xcode if you are on a mac, Visual Studio if you are on Windows). Inside the class declaration, add the following:
You also have to add a custom constructor declaration as well as a declaration for a collision component (in this example, a USphereComponent). This means that your C++ header will look something like this:
In the cpp file, write the following constructor:
Then add the following function definition to the code:
You can made additional changes in case you wish to only allow certain kinds of actors to destroy your destructible. For example, you can add code to specify that the destructible only be destroyed if the other actor is a subclass of a certain class, such as ACharacter.
Follow this question
Once you sign in you will be able to subscribe for any updates here