Hello !
I’m desperate right now : I want to make an energy source with a nice particle system which would heal my character if he steps on it. I created a collision box but nothing happens when he overlaps it
Here is my code :
SourceEnergie.h
/ Fill out your copyright notice in the Description page of Project Settings.
#pragma once
class APersoPrincipal;
#include "GameFramework/Actor.h"
#include "SourceEnergie.generated.h"
UCLASS()
class GHOST_API ASourceEnergie : public AActor
{
GENERATED_BODY()
public:
ASourceEnergie(const class FObjectInitializer& PCIP);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Source)
UParticleSystemComponent* Particules;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Source)
UBoxComponent* ProxBox;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Source)
UStaticMeshComponent* Mesh;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Source)
UAudioComponent* SonRendreVie;
UFUNCTION(BlueprintNativeEvent, Category = Collision)
void Prox(AActor* autreActor, UPrimitiveComponent* autreComp, int32 indexAutreBody, bool bFromSweep, const FHitResult & SweepResult);
};
SourceEnergie.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "ghost.h"
#include "PersoPrincipal.h"
#include "SourceEnergie.h"
ASourceEnergie::ASourceEnergie(const class FObjectInitializer& PCIP) : Super(PCIP)
{
ProxBox = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("ProxBox"));
Particules = PCIP.CreateDefaultSubobject<UParticleSystemComponent>(this, TEXT("ParticleSystem"));
Mesh = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("Mesh"));
SonRendreVie = PCIP.CreateDefaultSubobject<UAudioComponent>(this, TEXT("Son"));
RootComponent = Particules;
ProxBox->OnComponentBeginOverlap.AddDynamic(this, &ASourceEnergie::Prox);
ProxBox->AttachTo(RootComponent);
Mesh->AttachTo(RootComponent);
SonRendreVie->AttachTo(RootComponent);
}
void ASourceEnergie::Prox_Implementation(AActor* autreActor, UPrimitiveComponent* autreComp, int32 indexAutreBody, bool bFromSweep, const FHitResult & SweepResult)
{
if (Cast<APersoPrincipal>(autreActor) == nullptr)
return;
APersoPrincipal *persoPrincipal = Cast<APersoPrincipal>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0));
persoPrincipal->setVie(persoPrincipal->getMaxVie());
SonRendreVie->Play();
}
Thanks for your help !