Problem Creating Particle Effects in Tasks

Hi there,
I have a bit of an odd problem, which I’m hoping someone can help me out with. I’m working on a game that uses many different particle effects. Some are created using keypresses (using DirectObject.accept), while some are created in tasks. The following code, which can be called by a keypress or a task, is used to create all of them:

def showEffect(type, color1, color2, position):
   effect = self.particleFactory.createParticleEffect
                             (type, color1, color2)

ParticleFactory is a class that takes in a number of parameters and uses them create a new instance of a particle effect. Some code snippets from it:

class ParticleFactory:
    def createParticleEffect(self, type, color1, color2):
        if type == 'ball':
            return self.createBall(color1, color2)
    def createBall(self, color1, color2):
        ball = ParticleEffect()
        # set up particles
        return ball

The problem I’m running into is that particle effects generated when the showEffect function is called by a task don’t seem to be appearing on the screen, while those generated when the function is called by a keypress do appear.

The showEffect function is called with the identical parameters regardless of whether it is triggered by a task or a keypress, so I know the problem is somewhere inside the function. I have tried creating the particle effect when I start running and then just moving it with a task or keypress, and that seems to work. The problem only starts when I try to create a new one with a task.

Does anyone know why I can’t seem to create particle effects inside of a task?


why exactly do you create a particle effect from a task?
You should make sure, that if a task creates a particle effect it should only create one single effect…

If your task calls the particle efect over and over again, it will be reset and started from the beginning over and over again (if your code works as I think it does).

You might just put some print statements around your task and particle class to ensure that all calls are made correctly… (print statements are my favorite way of debugging).