Add dynamic fps game tutorial erro

i have problem with this code
CollisionComponent->OnComponentHit.AddDynamic(this, &AFPSProjectile::OnHit);

No matching member function for call to ‘__Internal_AddDynamic’

I don’t know how to fix it please help

106052-error+code.png

Hey Swagerbanana,

Do you have a declaration in your class for OnHit( )?

As an example:

[h]

#pragma once

#include "GameFramework/Actor.h"
#include "FPSProjectile.generated.h"

UCLASS()
class AH483955_API AFPSProjectile : public AActor
{
	GENERATED_BODY()
	
public:	

	AFPSProjectile();
	virtual void BeginPlay() override;
	virtual void Tick( float DeltaSeconds ) override;

    UPROPERTY( EditDefaultsOnly )
    USphereComponent *Collider;

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

[cpp]

#include "AH483955.h"
#include "FPSProjectile.h"

AFPSProjectile::AFPSProjectile()
{ 
	PrimaryActorTick.bCanEverTick = true;
    Collider = CreateDefaultSubobject<USphereComponent>( TEXT("Collider") );
    Collider->OnComponentHit.AddDynamic( this, &AFPSProjectile::Hit );
    SetRootComponent( Collider );
}

void AFPSProjectile::BeginPlay()
{
	Super::BeginPlay();
	
}

void AFPSProjectile::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );

}

void AFPSProjectile::Hit( UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult &Hit )
{
    
}

Yes I have

// Function that is called when the projectile hits something.
UFUNCTION()
void OnHit(class AActor* OtherActor, class UPrimitiveComponent* OtherComponent, FVector NormalImpulse, const FHitResult& Hit);

The delegate was changed a couple engine versions ago, meaning your OnHit function doesn’t follow the necessary argument list.

Please update it to what is below and let me know if that works:

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

its not work to me there the full code

h
106159-
cpp
106160-

You are still using the wrong OnHit.

Again:

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

As a reminder, the parameters are different. Look at your code, then look at this one to see the differences and try again.

Thanks.

I know I used the code you send me but it’s not work

you think in unreal editor

The code you posted isn’t what I posted.

Aside from that, what does it say when you compile?

I don’t understand what you mean by that. Can you explain further?

you mean compile in unreal editor or in Xcode

If in Xcode it’s not work

Try the UE4 editor, please and let me know what it says in the Output Log. If your Output Log isn’t open, you can open it by doing the following:

On the top menu bar, left-click on “Window” then go to “Developer Tools” and finally, select “Output Log”.

When i compiled it its says
106204-

Can you post the exact code you have now for your FPSProjectile?

cpp
106231-
h
106232-

Change:

[h]

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

[cpp]

void AFPSProjectile::OnHit( class AActor* OtherActor, class UPrimitiveComponent *OtherComponent, FVector NormalImpulse, const FHitResult& Hit )
{
    If( OtherActor != this && && ->IsSimulatingPhysics( ) )
    {
        OtherComponent->AddImpulseAtLocation( ProjectileMovementComponent->Velocity * 100.f, Hit.ImpactPoint );
    }
}

To:

[h]

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

[cpp]

void AFPSProjectile::Hit( UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult &Hit )
{
    if( OtherActor != this && ->IsSimulatingPhysics( ) )
	{
		OtherComp->AddImpulseAtLocation( ProjectileMovementComponent->Velocity * 100.f, Hit.ImpactPoint );
	}
}

now I’m haven’t got a error but my projectile not push the cube on the level

tutorial section
link text

Check out the First Person Template in C++. It has everything you’ll need to understand about the projectile hitting a simulated physics mesh.

i don’t find why my projectile not push the floor static mesh do you help me