I’m trying to access a game objects mesh from a Babylon class component (.cs)
//MyScriptComponent.cs
[BabylonProperty]
public GameObject swap;
//MyScriptComponent.ts
this.getProperty("swap", null)
But when I try and access the mesh swap.visibility = true;
There’s no game object properties that I have access to and I don’t know how to access or get these properties, so what’s the best way to access a defined mesh from the inspector with the toolkit? Preferably from a GameObject.
You can’t do it like that in the classic version. It’s an Exporter … the easiest way to get a reference to a mesh in Babylon are the scene get mesh by name functions. In the new versions I support transforms and game objects by serializing the MeshID then in your script component you will have a string property with that MeshID and use scene get mesh by ID to get a reference to a separate mesh… you can do that yourself in your script component until the new version is ready
I’ll check what is serialized later today. But I think that ID in the image above is the mesh id… use that to get a reference to the mesh. That should work for now.
What mesh did you have assigned to the swap variable … powerbardcords_unplugged ???
If it’s not a mesh… then use one of others… get node by I’d should return anything . Or you could use get transform node… also use the inspector and look at the id… is that the right node/game object
Can you send me your scene… package up as a unitypackage … I’ll take a look at what’s going wrong…
Also … not sure the scene manager in the classic version will work with latest Babylon engine… I’ll try update the engine later this week when I get a chance
Use the inspector and expand the Nodes… take a screen shot and let’s see what actually in your scene… I can’t really debug without the scene. The one example I sent has every thing in it…
FYI … everything in Babylon is either a mesh , a light or a camera… game objects with no geometry is a transform node.
So even though the Sphere in unity says it’s a game object… in Babylon it will be a Babylon.Mesh
It’s not the inspector its the actual code that I’m debugging, it’s the exact same thing just not the inspector, this is the mesh that I’m getting from the Babylon mesh component from the Gameobject:
And this is the null value I get when I try and getNodeById():
I copied your code exactly and understand what should be happening, it’s just not getting mesh or node, the gameobject is a Gameobject with a mesh component:
I just realized what it was @MackeyK24 I have the object turned off in the unity inspector and because of that it’s not finding it in the scene, I had no idea: