Instantiate object with properties

Hello Needle,

I would like instantiate an object, but I got a problem : when I instantiate it, all of my components and objects are correctly instantiate but not their properties.
And I use this properties added to manage them. (like isSomething = true) to easily designate them.

Do you have a solution to keep it ?

Original Post on Discord

by user 224464722878005248

Hi, can you provide more information?

For example,

I want to generate an object with different object3D in there, like a motor (it could be anything)
I added different properties in my mainObject like pistonList = which list the objects and each piston get a property isPiston = true in their properties.

Like it, if I want to regenerate pistonList, I do a .traverse in my mainObject (my motor) and if obj.isPiston : pistonList .push(obj) etc

I thought about using the name to do it but if there is another solution I take it

by user 224464722878005248

You have 2 options:

  • use the objectā€™s userData three.js docs (but be aware that if you instantiate it then userdata might be shared between your objects!)
  • add a component with your data and add it to the object (using GameObject.addNewComponent & GameObject.getComponent(...))

Okay thanks !

by user 224464722878005248