Sometimes when playing a bunch of scripts crash and I get this error:
This has happened 2 times now. Anyone know what could be causing it?
Sometimes when playing a bunch of scripts crash and I get this error:
This has happened 2 times now. Anyone know what could be causing it?
It has now happened 5 times. It happens the same way every time:
The player spawns with a grenade launcher. Just keep exploding the cylinders and eventually it breaks.
ALUCARDS LETHAL MUNITIONS EXPO | Launch
Alright so after more testing just existing within the game not doing anything for about 4 minutes breaks the game.
After more investigating this only occurs with the grenade launcher active, I believe it may be some memory leak. This is the relevant code pieces
if (this.grenadelauncher === true)
{
this.thenade = this.nade.clone();
}
if (this.grenadelauncher === true)
{
this.Nadelaunch();
}
else
{
this.Shooty();
}
Gun.prototype.Nadelaunch = function() {
this.bulletentity.children.forEach((enabloid) => {
enabloid.enabled = true;
enabloid.setLocalEulerAngles(0, 0, Math.random()*360)
});
this.thenade.reparent(this.app.root);
this.direction = this.nade.parent.up.clone();
this.direction.scale(this.launchpower);
this.thenade.rigidbody.applyImpulse(this.direction);
this.thenade.setPosition(this.nade.getPosition());
this.thenade.setRotation(this.nade.getRotation());
this.thenade.enabled = true;
};
var Mikemike = pc.createScript('mikemike');
// DAMAGE GRENADE DOES PER PELLET
Mikemike.attributes.add("damage", {
type: "number",
});
// NUMBER OF EXPLODEY PARTS
Mikemike.attributes.add("pellets", {
type: "number",
});
// TAG IT DAMAGES
Mikemike.attributes.add("enemytag", {
type: "string",
});
// MAX RANGE OF GRENADE
Mikemike.attributes.add("range", {
type: "number",
});
// A SEPARATE ENTITY IS REQUIRED BECAUSE THIS ENTITY GETS DISABLED SO IT WONT FINISH THE SOUND
Mikemike.attributes.add("soundplayer", {
type: "entity",
});
Mikemike.prototype.initialize = function() {
this.entity.collision.on('contact', this.onContact, this);
};
Mikemike.prototype.update = function(dt) {
if (this.killme === true)
{
this.entity.destroy();
}
};
Mikemike.prototype.onContact = function (result) {
for(i=0;i<this.pellets;i++)
{
this.entity.setLocalEulerAngles((Math.random() * 360), (Math.random() * 360), (Math.random() * 360));
anglePos = this.entity.forward.clone();
anglePos.scale(this.range);
from = this.entity.getPosition();
result = this.app.systems.rigidbody.raycastFirst(from,anglePos.add(from));
if(result){
if(result.entity.tags.has(this.enemytag)) {
result.entity.name = ((parseFloat(result.entity.name)) - this.damage);
Globaldamage += this.damage;
};
};
}
this.entity.children.forEach((entity) => {
entity.enabled = true;
});
this.soundplayer.sound.play("sound");
this.killme = true;
};
Ok so you do have a memory leak somewhere given the error code. The error you got specifically refers to you creating to many rigidbodys.
Perhaps the cloning is to blame? I will try to run it, then run it again without the clone function.
I just moved the clone to the firing function and it works
Wait you were cloning it every update?
oh yeah
I thought that this.thenade = this.nade.clone(); would mean that this.thenade would always be set to a single clone of the entity, I did not realize that it was cloning the entity repeatedly every frame.