x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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?

Product Version: UE 4.9
Tags:
more ▼

asked Oct 29 '15 at 05:28 PM in Using UE4

avatar image

Bifron
6 1 3 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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:

 /** called when projectile hits something */
    UFUNCTION()
    void OnHit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);

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:

 class YOURGAMENAME_API ADestructibleActor : public AActor
         {
             GENERATED_BODY()
         protected:
 /** Sphere collision component */
     UPROPERTY(VisibleDefaultsOnly, Category=Projectile)
     USphereComponent* CollisionComp;
             /** called when projectile hits something */
            UFUNCTION()
            void OnHit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
     
     public:
     ADestructibleActor(const FObjectInitializer& ObjectInitializer);
             
         };   

In the cpp file, write the following constructor:

 AFPSProjectile::AFPSProjectile(const FObjectInitializer& ObjectInitializer)
         : Super(ObjectInitializer)
     {
         // Use a sphere as a simple collision representation
         CollisionComp = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("SphereComp"));
         CollisionComp->InitSphereRadius(15.0f);
 CollisionComp->OnComponentHit.AddDynamic(this, &AFPSProjectile::OnHit);
         RootComponent = CollisionComp;
     }

Then add the following function definition to the code:

 void ADestructibleActor::OnHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
    {
        if ( OtherActor && (OtherActor != this) && OtherComp )
        {
            Destroy();
        }
    }

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.

more ▼

answered Oct 29 '15 at 07:39 PM

avatar image

Alonzo Machiraju
62 12 15 20

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question