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"

OnParticleCollide event not triggering

Hi

I'm currently trying to spawn blood decals when blood particles hit the floor. To achieve this I added an event generator of type collision on the particle system and I tried to bind the event to a function. However the bound function OnBloodParticleCollide is getting triggered. I can't seem to find what I'm doing wrong, also my code seems to be styled in a weird manner in this post. I've seen other posts that had a way better representation of the code. Is there a better way to style it?

        GEngine->AddOnScreenDebugMessage(-1, 20.0f, FColor::Cyan, TEXT("Bind on particle collide"));
         TScriptDelegate<FWeakObjectPtr> particleCollide;
         particleCollide.BindUFunction(this, "OnBloodParticleCollide");
         particleSystemComponent->OnParticleCollide.AddUnique(particleCollide);
 
 .h
     UFUNCTION()
             void OnBloodParticleCollide(FName EventName, float EmitterTime, int32 ParticleTime, FVector Location, FVector Velocity, FVector Direction, FVector Normal, FName BoneName, UPhysicalMaterial* PhysMat);
 
 .cpp
     void AProjectile::OnBloodParticleCollide(FName EventName, float EmitterTime, int32 ParticleTime, FVector Location, FVector Velocity, FVector Direction, FVector Normal, FName BoneName, UPhysicalMaterial* PhysMat)
     {
         GEngine->AddOnScreenDebugMessage(-1, 20.0f, FColor::Cyan, TEXT("Blood colliding"));
         if (BloodDecalMaterial)
         {
             float randWidth = FMath::RandRange(20.0f, 20.0f);
             UGameplayStatics::SpawnDecalAtLocation(this, BloodDecalMaterial, FVector(20.0f, randWidth, randWidth), Location, Normal.Rotation());
         }
     }

test

Product Version: UE 4.22
Tags:
particles.png (104.9 kB)
more ▼

asked May 19 '19 at 06:22 PM in C++ Programming

avatar image

Para96
11 5 6 8

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

1 answer: sort voted first

This is solved, I was binding the function to my projectile which gets destroyed after spawning the particles. This meant the object that was waiting for the onParticleCollide was no longer available and the function was not executing.

more ▼

answered May 25 '19 at 06:04 PM

avatar image

Para96
11 5 6 8

(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