We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

how to refer to cloned objects in events puzzles

Home Forums Puzzles how to refer to cloned objects in events puzzles

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #42541
    fressfisch
    Participant

    Hi

    I’m trying to change a cloned object’s material by clicking on it.
    I already figured out how clone the object and save it as a variable into a previously created list. However refering to that variable does not seem to work. What am I doing wrong?

    Also I’m want to display an outline on hovered objects (see secend attachment). This works on existing objects, yet again not on their clones.

    Attachments:
    You must be logged in to view attached files.
    #42556
    xeon
    Customer

    Hi there,
    I reviewed your code and it seemed correct so I created my own and worked backward from there. Changing a clone’s material can be tricky but there are two possible solutions that may solve your issue.

    I started with a cube (the main object) and a plane. The plane has a red material assigned to it and the default cube has a white material assigned to it. As I am sure you know in order to change materials the materials have to already be in the scene before you can make the switch so if you wanted to change all the cubes to red and then back you would need another plane that has the white material to make that happen.

    With that out of the way…you are doing this with lists.
    As you probably already know clones of an object get an incrementing number to append to the original object name. So if the original object is Cube, the first clone will be called Cube2 and the second called Cube3.

    Since you are storing these in a list they will be associated by position in your list as:
    position 0 = Cube2
    position 1 = Cube3
    in this example at least.

    So the below code example starts with a single cube.
    Creates an empty list – called “cloned cans”
    I also create a variable called MyCanX which is the distance of X between each clone that will be created.
    I created a simple loop to clone the cans, set the cube position and then set the clone colors to red.

    Depending on how many clones you create, you may not know the name of a particular clone object but you know how many clones you created. I only have two in this example so I didn’t do anything elaborate with the onclick events and any logic to have a universal onclick and then determine if the object was in the list…but this will get you going.

    I provide my code solution so you can see how I refer to them but nothing wrong with the way you are doing it.

    After this I recreated your code and found a few things to be sure you are doing to ensure your code works. Your code itself is fine….so I am thinking its one of the two items below that has things not working.

    1. Make sure you create your empty list_furniture at the start of your puzzle scenes…this should be an early initialization. You are probably already doing this but just not in the puzzle image supplied. If it’s not initialized before the onclick call the material will not transfer to the clone…and the click will just be ignored. You can test if your onclick is being ignored by placing a Print to Console in the onclick event.

    2. Make sure you have the “gray” material in the scene on an object prior to requesting the material to be changed. I usually create a bunch of small material squares and hide them somewhere in the scene so they are all preloaded and available.

    For the last part of your question the outline of the clones on hover.
    As long as you onclick event is firing, your on hover outlines will work as long as you have outlining turned on in your 3D scene before you export it to GLTF.

    Hope this helps.

    Attachments:
    You must be logged in to view attached files.

    Xeon
    Route 66 Digital
    Interactive Solutions - https://www.r66d.com
    Tutorials - https://www.xeons3dlab.com

    #42561
    fressfisch
    Participant

    Thank you so much, it actually works now!
    I did initialize all lists in the beginning, but I also had a procedure to remove them before creating new objects (as I’m working on an exhibition booth configurator). So I just adjusted the order and that solved it. Same with the outlines.
    Your solution actually also solved some problems I would have run into along the way, so again, thank you!

    #42580
    xeon
    Customer

    Glad it got you on track. Would love to see the final product when you are done.

    Xeon
    Route 66 Digital
    Interactive Solutions - https://www.r66d.com
    Tutorials - https://www.xeons3dlab.com

    #71206
    c4cc
    Participant

    Your code itself is fine….so I am thinking its one of the two items below that has things not working.

    1. Make sure you create your empty list_furniture at the start of your puzzle scenes…this should be an early initialization. You are probably already doing this but just not in the puzzle image supplied. If it’s not initialized before the onclick call the material will not transfer to the clone…and the click will just be ignored. You can test if your onclick is being ignored by placing a Print to Console in the onclick event.

    2. Make sure you have the “gray” material in the scene on an object prior to requesting the material to be changed. I usually create a bunch of small material squares and hide them somewhere in the scene so they are all preloaded and available.

    Sorry for replying to an old thread, but why are you repeatedly fixing click and hover puzzles for each clone?

    Is it not possible to use loop functions through the clones, so that click and hover puzzles area
    Are only used once while they loop through the clones?

    • This reply was modified 2 months ago by c4cc.
    • This reply was modified 2 months ago by c4cc.
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.