Hi PlayCanvas Devs,
I want to copy (“clone”) an entity with attached spine character at runtime.
When I clone the entity in the “Initialize” method, the spine character is visible as intended.
But when I clone the entity after the “Initialize” method (E.g. on click or in postInitialize), the spine character is not visible.
Here is a sample project:
Observe: The first Hero is cloned successfully (in Initialize), but when you click, the cloned entities don’t render their Spine components.
In addition, it throws the following warning:
addComponent: Entity already has spine component
@will has some hints?
Any hints appreciated
January 13, 2020, 7:13pm
It is because the spine is added a second time on a click.
You create a clone on initialize. At that time a clone is created without a spine properly.
spine.js is loaded by the engine afterwards, because it is attached to enabled entity
Hero, and it’s
intitialize is fired, bringing you to your current problem.
Here is a fix:
Hero entity from the Editor and disable it.
And in your code, the clone will be disabled initially too, so just enable it after cloning:
// create clone
var clonedHero = this.originalHero.clone();
clonedHero.enabled = true;
Now, since your Hero entity is disabled, the engine will not execute the
spine.js attached to it automatically.
I also noticed you check your assets like this:
if (this.atlas && this.textures && this.skeleton)
You would want to check if you get a proper boolean from that. I think this way is a proper one:
if (this.atlas !== null && this.textures !== null && this.skeleton !== null)
Here is a
@LeXXik thanks a million for your help!
Disabling the entity in the editor works like a charm. Sure it is a workaround (quite error-prone and not intuitive to work/iterate on the entites) but it fixes the initial issue - which is great!
asset-check suggestion might interest @max @vaios or @dave - because it is part of the PlayCanvas spine plugin.
Have a nice day,