How do I clone an instance of an object?

0 favourites
  • 7 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • I am trying to clone multiple instances of the same object, (each with unique instance variables that need to be maintained) The trouble is with "create new object" or "spawn object" it puts all the instance variables to the defaults. And due to picking behaviors it is difficult to associate the new object with its parent, to inherit its variables. Any help would be appreciated.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • After the create event, the clone is automatically picked. Just set its variables directly after.

    Edit: When you create your parent object, just save its uid somewhere like a global variable. You can then set the clones variables using the saved parent reference.

  • Right, that's not the issue though, its bringing the variables from the other instance. if I go "Create object, ObjectA" then "Set instance variable ObjectA, Variable1= ObjectA.Variable1" it thinks I am referring to the object I just created, instead of the preexisting one when setting the new variable

  • Right, that's not the issue though, its bringing the variables from the other instance. if I go "Create object, ObjectA" then "Set instance variable ObjectA, Variable1= ObjectA.Variable1" it thinks I am referring to the object I just created, instead of the preexisting one when setting the new variable

    Just edited my answer

  • I think that'll work in spite of the scale I am doing it on, I just can't figure out how to make that reference in the set instance variable window

  • Pick the one that you want to 'clone'. (and only that one, do not create a picklist containing more sprites)

    Store its expression Sprite.AsJSON in a local text variable.

    Create object somewhere outside screen or so, does not matter.

    Use the action .... Sprite > Set from JSON ... to set the Just Created sprite to the local variable.

    The 'clone' should now be exact.

    Meaning, now you have to set its positions and other things that that you want to be different.

  • Oh thank you! That sounds like it will work perfectly, alternatively I was going to save the parent variables to an array, but it seems more intensive than simply doing what you said. (since its a small repeating process 0-4 times)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)