[SOLVED] Undefined model property

Hello,

There is a strange model-related problem in our project (https://playcanvas.com/project/424770/overview/hotel-showcase). We have two nearly identical mirrors; each consists of a camera and a model to which the mirror texture is applied. The script for the mirror effect is attached to the camera, and name of the “target” model’s node is passed as an attribute.

A somewhat similar error is here (☑ model.meshInstances throwing core error?) but it seems to be related to an entity’s lifetime while in our case it’s the entity’s name that causes problems.

One of the mirrors (in the hallway) works while another (in the bathroom) doesn’t. The script searches for a node like this:

this.mirrorSurface = this.app.root.findByName(this.surfaceName);

this.surface name is currently either “bathroom_mirror” or “hallway_mirror”. The problem is, for the bathroom mirror, “this.mirrorSurface.model” is undefined. Thus, we cannot get meshInstances.

Below are the screenshot of the non-working nodes in the Google Chrome debugger. The node indeed has no “model” property but for some reason has a child named “mirror_body” which our modeller deleted some time ago.

What’s more, we created an exact copy (“bathroom_mirror2”) of the original bathroom_mirror node, attached to it the same model’s JSON file and passed the new name (“bathroom_mirror2”) to our mirror script. The script worked. Then we deleted the original node (“bathroom_mirror”) and renamed our new node to “bathroom_mirror”. The script stopped working with the exact same error.

Our modeller thinks the engine somehow remembered the old info about the deleted model. Of course, the problem is easily solved by renaming the mirror model’s node but we thought this post may help to solve someone else’s problem.

That’s REALLY odd. The *.model should be a component on the entity. For it not to be added is really strange.

The problem is that there are different entities which seem to have the same name as children. For example in the case of bathroom_mirror there is another Entity called bathroom_interior which has a child called bathroom_mirror - It’s not visible in the Editor it’s just the name of a mesh instance. So when you do findByName that entity is found first which does not have a model component.

Instead of findByName I suggest you declare script attributes of type ‘entity’ and then drag and drop the actual entity you need on the script.

1 Like

I remember debugging a similar issue with @ayrin’s project a while back and it’s can a be a bit tricky to debug if someone hasn’t come across it before. I guess the first clue should have been that this.mirrorSurface is a GraphNode and not an Entity type?

1 Like

I just checked the names of all the parents of the Entity in the console.

That would work :no_mouth:

For some reason, I hadn’t even consider mesh names, although the GraphNode type did look suspicious…

Thank you all for your time and clear explanations! Using attributes of type ‘entity’ is certainly better.

P.S. Couldn’t decide who should mark the question as “[SOLVED]” but guess it can be me.