Custom Explosive fails to spawn particle effects

Hello,

I have created a rather large explosive entity set to explode and remove itself on contact.
When it explodes, it is to call upon a custom particle effect that exists in another class.

However, in Singleplayer, this effect fails to occur about 30% of the time. And in multiplayer this effect does not spawn at all.

I have a hunch that it is because the entity is removing itself too quickly before the particles can be called upon, but I know the answer is NOT setting a timer to make it remove shortly after it explodes.

Can anybody pitch some advise as to how to solve this?

Here is the entity’s class.

And here is the particle effect’s class.

Thank you for your time.

I actually figured it out… kinda

I was using a ENT based function for calling on the effect, for an ENT that does not exist anymore.

I replaced it with util.Effect, setting the origin of the effect to the Position of the Physics collision of the entity, so everything works…

In Multiplayer only.

That’s good enough! Well done :joy:

For anyone who comes upon this with the same problem,
I figured it out for real.

In the Effect:INIT function inside of the effect’s class, I put everything inside of an

if isValid(data:GetEntity()) condition, meaning that if the entity was no longer valid, the effect would not spawn.

Obviously when a bomb explodes, the bomb itself is no longer valid because it removes itself.

And being I set the explosion’s origin to the location of the physics impact HitPos being this is a contact detonated grenade. There was no reason I needed to tie anything to the entity itself, let alone depend it on the entity being valid.

The reason I had this check in the first place was that when I called upon custom effects for my other weapons, I needed this check in case the player died while firing some of them to prevent any nil errors.

Long story short.

If you’re making a contact detonated explosive, set the effect origin to the location of the physics contact, rather than the bomb’s location itself. Should be much more dependable especially on multiplayer from my experience.

Cheers.