OnHit UE_LOG not being called

Hello,

I have review my code a couple times over, but I’m stumped for now as why OnHit isn’t being called during play. This is my code:

CPP
    UTankTrack::UTankTrack()
    {
    	PrimaryComponentTick.bCanEverTick = true;
    }

    // Called when the game starts
    void UTankTrack::BeginPlay()
    {
    	OnComponentHit.AddDynamic(this, &UTankTrack::OnHit);
    }

    void UTankTrack::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, FVector NormalImpulse, const FHitResult& Hit)
    {
    	UE_LOG(LogClass, Warning, TEXT("I'm hit..."));
    }

HEADER
    UCLASS(ClassGroup = (Tank), meta = (BlueprintSpawnableComponent), hidecategories = ("Lighting"))
    class BATTLETANKS_API UTankTrack : public UStaticMeshComponent
    {
    	GENERATED_BODY()
    	
    public:

    	UTankTrack();
    	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
    	virtual void BeginPlay() override;


    	UFUNCTION(BlueprintCallable, Category = Input)
    		void SetThrottle(float throttle);

    	//In newtons (N)
    	UPROPERTY(EditDefaultsOnly)
    		float maxDrivingForce = 400000; //10m/s^2

    private:

    	UFUNCTION()
    		void OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, FVector NormalImpulse, const FHitResult& Hit);
    	
    	
    };

I’m running 4.15.2. Is it possible they changed it again? Any help is appreciated!

I found the culprit. Either it is turned off by default, or somewhere in the course we disabled “Simulation generates” under Collision on the tracks:

4 Likes

Thanks a lot! I had this problem myself.

Its “Simulation Generates Hit Events” to be exact and its by default set to false, this is the exact naming currently on 4.21 which should be set to true for Hit event to work on Physics collision enabled bodies

Privacy & Terms