Particle system problem

Hi gyus.
I’m trying to learn how to use Particle System and i need some help.
Please, check this project.
When a player is loaded, press C and fireball appears.
I don’t know why, but the first time you cast fireball the game “freezes” for a moment. Is there a way to avoid it?

Also i want to ask about performance with particle systems.
What should i pay attention to if i want my game works fast and particles looks great? I think particles count and emission rate are the most important parameters influence of game performance.
Thanks in advance.

As the entity is disabled on launch, the components don’t get initialised until it is enabled for the first time which may mean some shader compilation, hence the frame drop. (@dave should know more). To get around this, you can have it enabled on start of the application (out of the camera view) and disable it on postInitialize.

On a side note, when you clone an entity, you need to give it a parent otherwise it shouldn’t be shown. I don’t know how it’s working now but you should change the Paladin.prototype.castSpell to:

Paladin.prototype.castSpell = function(spell) {
    if (spell == 'fireball') {
        var firebalEntity = this.app.root.findByName('fireball').clone();  
        this.app.root.addChild(firebalEntity);
        firebalEntity.setLocalPosition(0, 1.716, -1);
        firebalEntity.enabled = true;
        firebalEntity.script.movingSkill.setTargetPos(new pc.Vec3(0, 1.716, -10));
    }
};

I see. Thanks for the info.

I’ve just tried to use ur work around:

Network.prototype.postInitialize = function() {
    this.initializeEffects(['fireball', 'explosion']);
};

Network.prototype.initializeEffects = function(effects) {
    for (i = 0; i < effects.length; i++) {        
        this.app.root.findByName(effects[i]).enabled = false;
    }
};

Particles are enabled by default.
And still the problem remains.

I see this:

Looks OK to me. What’s the problem exactly?

The first time the knight casts fireball game freezes for a moment. After that everything is ok.