playMaker

Author Topic: Create a duplicate of a Game Object  (Read 3150 times)

szomaza

  • Sr. Member
  • ****
  • Posts: 253
Create a duplicate of a Game Object
« on: March 15, 2016, 01:59:31 AM »
Hi,

Is it possible to simply create a duplicate of a game object during runtime, along with all it's child objects and all parameters of it's components?

What I am doing is loading in game objects by merging scenes, but in some cases I would need 2 of some of those game objects.
I searched but could not find anything, like a PlayMaker action to do this duplication.

Action would simply: duplicate game object stored in variable, and save newly created object in another variable.
Am I dreaming?

Instead this, I believe I could use a bunch of get component, get property and set property actions, add FSMs to them, etc. but that could get complicated ... for me.

Or I could save each different object (I'll eventually have hundreds) into prefabs and simply spawn 2 of each, where required.
Then I would not need the whole: loading them by merging a level part, but spawning many prefabs does have a huge hit on performance.

Please shed some light, how I should proceed or share your experience/solution to similar problem.

Br,
szomaza

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Create a duplicate of a Game Object
« Reply #1 on: March 15, 2016, 05:54:19 AM »
Hi,
You can use the "Create Object" action for this.

In Game Object place your object you want to create (or duplicate)
This can be an Object from the scene, it can be a prefab and it can be a Game Object inside a variable.

just be careful with actions inside the Game Objects created (especially from prefabs) that are connecting to objects inside the Scene.

Zeldag

  • Full Member
  • ***
  • Posts: 198
Re: Create a duplicate of a Game Object
« Reply #2 on: March 15, 2016, 01:33:25 PM »
I think i remember doing something simmilar ages ago by using 'get owner' and 'create object'. Cant remember if it was flawless or if i resorted to a prefab in the end. It was just for experimenting and never used it.

How i did it:

On the object you are duplicating add a 'get owner' action (save to variable).

Then create object and use the variable you saved to.

I think that should work, but ill see if i can find the ancient project when im at the computer.

Good luck with it.

Edit to add:

The poster above is basically right i think, you can just drag any object to create. Using 'get owner' often solves the issue djaydino mentioned in the last paragraph (prefabs connecting to scene objects) and is useful whenever you need scene objects to interact with prefabs.
« Last Edit: March 15, 2016, 01:49:35 PM by Zeldag »

szomaza

  • Sr. Member
  • ****
  • Posts: 253
Re: Create a duplicate of a Game Object
« Reply #3 on: March 17, 2016, 02:16:08 AM »
Thank you guys!
I confirm that it works.

And I am mind blown as I have been using Create Object for ever but only with prefabs, didn't know you could make a duplicate of something in the scene with it.

Br,
Szomaza