Bug in order of entities in editor

I discovered a problem in the order of entities in the editor that prevented the script from running correctly. This has happened to me a few times now.

For example:
In the left image i can enabled the FlashLightLamp by script. In the right image not.
In this example the diffrent is the order of the Model.
Naamloos

In Unity you can live see in the editor what is happening in the play mode.
It’s pity that this is not possible with playcanvas.

Yes, indeed that would be quite useful, seeing the run time entity hierarchy.

Regarding your issue, I imagine it is a matter of the order the code is executed. Could post some more info on where is your script is attached to and how you run the code that enables the FlashLightLamp entity?

The FlashlightLamp get enabled in the player script that is an attachment of the Player entity.

Could you share some code or a sample project that reproduces the issue?

If it is a bug it will be very useful to get a repro, so it can be fixed.

I think it only has to do with .enabled in combination with the order of the entities in the editor.

Another example:
In this image all entities are cloned correctly in game:

In this image only the barrels are cloned correctly in game:

From what I understand the Barrel, Rifle, Knife entities all have the Cloner script attached?

The initialize method will run only when the entity gets enabled for the first time. So even though the entities are created and added to the hierarchy as prefabs, since they are disabled your code won’t execute.

Usually what I do is have a manager entity somewhere on the Root or the Prefabs entity, in your case, that manages the cloning/spawning of entities. That manager script can get a reference to a disabled prefab, clone it and enable the spawned entity.

Yes, the Barrel, Rifle and Knife entities all have the Cloner script attached. But you don’t see this entities on the images. This entities are enabled in the editor. On start of the game the entities in the editor will be replaced by the cloner script for the prefab entities that you can see on the images.

I do this because if i make a change in a prefab i don’t have to change all objects in the scene.

Mmm, I can’t understand out of my head then what’s going on.

I don’t think there is a bug though. I’ve been working with complex projects with a lot of entities and if I respect the order Playcanvas adds and executes the script callbacks everything works as expected.

If you still experience the issue, do try to post some sort of a repro project to help with debugging your issue.

Yes, i think it is a bug. In both examples i don’t change anything excepted the order of entities in the editor.

So in the second example: If i place the barrel prefab entity after the knife and rifle entities the script works correcly, but if a placed the barrel prefab entity before the knife and rifle entities there is a problem…

Maybe then try raising an issue on the github repo about this:

Sorry but my knowledge is insufficient for that.

But if you think it’s not a bug, I don’t understand that only the order can cause a problem in these two examples.

For me it is not a problem now, I just wanted to let you know …

I know it might not always be easy to share a project or build a repro sample project, but in several cases it is the fastest way to get help on issues like that.

You can take a look in my project if you want? Just tell me what i have to do.

If it is a public project, share the project link here or with a PM to me.

If it is a private project, add me, temporary, by clicking Edit on Team at the project setting:

You can use my Playcanvas username: leonidas