Hi, how are things?
I have a problem with the enabled yesterday everything was fine, but today when I start the game it doesn’t work for me when I install the template.
We’re still discussing this change.
entity.enabled returns true if entity is enabled itself and also if it is enabled in the hierarchy (which means its part of the scene)
There was an issue where entity removed from the hierarchy still had enabled in the hierarchy
set, which is incorrect, and this is what was fixed.
So at a guess … your entity is not in the hierarchy, as so .enabled is false. But ._enabled would be true.
But when your entity is added to the hierarchy, .enabled would be true as well.
related PR https://github.com/playcanvas/engine/pull/4054
Does this help you?
I am looking at it and I did not have this blue line added to the code, but when I add it there is no effect, what you say is true was not added to the hierarchy and I get _enabled = true, but it still does not work when I add it.
So what is the problem? What do you mean by ‘it still does not work’?
Could you perhaps create a small repro project?
My project is practice to learn, is this
https://playcanvas.com/project/887494/overview/proyecto-2-space-invaders
It had been working great but today when I got back to the project it stopped working, and I quit it fine on Saturday.
I am using pool algorithm for templates.
I hope you can help me, I am reading what has happened before, but I don’t understand how to apply it to my case
Hi @FSCV,
I just want to mention in case you haven’t seen, but you can revert to the previous version of the engine while we look into this issue.
Go to scene settings → EDITOR → Engine Version and select ‘1.51.7’.
With this I can continue working, but I understand that it is a temporary solution, since if I reload then I have to change the version again.
That’s correct, but you can also publish using the older version of the engine if need be to.
We will investigate the issue
Thank you very much for the prompt attention
I’ve had a look at the project and it looks like when you remove the item from the pool, it isn’t added to the scene graph.
In TEMPLATE.js, I’ve just made the change in the spaw
function:
self.spaw = function () {
var item = pool.shift() || father.clone();
// This line
item.reparent(pc.Application.getApplication().root);
return item;
};
And that looks like it works in this forked project: https://playcanvas.com/editor/scene/1362290
Actually, I’ve just made it a little tidier so that there is a parent under the application root that holds all instances.
function TemplatePool(name) {
let self = this;
var pool = [];
var assets = pc.app.assets.find(name, "template");
if (!assets) console.log("NAME: " + name + " NO ASSETS");
var father = new pc.Entity(name + ' container');
pc.app.root.addChild(father);
father.enabled = true;
self.spaw = function () {
var item = pool.shift() || assets.resource.instantiate();
item.reparent(father);
return item;
};
self.remove = function (item) {
item.enabled = false;
pool.push(item);
};
}
Which looks like this at runtime:
You have a bug around the hit entities (laserRedShot in the screenshot above) not using the pool but that looks like a project specific issue rather than an Engine issue
I’ve fixed the issue where laserRedShot is not being pooled correctly. I think there’s an issue where the Entity name is different depending on if the asset name of the Template was changed since been created and if the template is instantiated via code or placed in the Editor
Via code uses the Entity name that was used when the asset was created and when placed in the Editor, it changes it to the asset name.
I’ve worked around the issue by explicitly changing the name of entity when a new instance is created. This has been done in the fork above if you want to check the code
Thanks, I’m going to take a look at the forked project and fix mine.
In fact, I applied the solution you gave me with the logic of the pool algorithm and it turned out very well, thank you very much.