BabylonJS / BabylonToolkit

Home of the community maintained Unity & Unreal exporters for Babylon.js
173 stars 46 forks source link

Get object mesh and material at runtime #36

Closed Wally869 closed 2 years ago

Wally869 commented 2 years ago

I've got a simple unity scene with a single quad on which a texture is applied and I'm trying to access this material in my controller to change main texture offset at runtime. My problem is that I'm not sure how to get a reference to this material.

Calling the material property on the meshes returned from getAbstractMesh and getTransformMesh returns a collider material, while getInstancedMesh does not seem to have a material attached.

I have managed to get a reference to the material I'm interested in by getting the material by name in the scene.materials list and then applying the offset as I wanted to do, but I'd like to know if there is a better solution that I've missed.

MackeyK24 commented 2 years ago

You are using physics collisions... That older version... the collider is the parent and the actual mesh is the child... look for the child detail mesh... get material from that...

Newer version of the toolkit DO NOT reparent simple colliders anymore. So no need to look for child detail mesh