Jump to content

registerBeforeRender on childmeshes created in "for loop"


Recommended Posts

Just for understanding - 

What you did it working. But only for the last sphere defined :) The async function you register (in the registerBeforeRender) is using the sphere variable reference. As sphere is defined in the scope above it, and javascript hoists variables, the sphere reference inside this function always directs to the last sphere you created. @aWeirdo (Hey, I always find it hard calling you that :) ) suggested a great way of solving this.  Personally, I like using the forEach function over arrays, as it creates a new context each time you run it. If you want to register a function for each sphere, this is how I would to this:


I find it cleaner, but it is all a matter of taste in that case.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...