cancel
Showing results for 
Search instead for 
Did you mean: 

Duplicating objects with scripts

Sopwyth
Explorer

Is there a way to duplicate complex objects with scripts? I was trying to duplicate bows from the launching template and no matter how much I clear stuff out of the way and try to circle everything around the bow, the duplicate never has a string that works.

1 ACCEPTED SOLUTION

Accepted Solutions

teerez83
Protege

Ah ok. I think I somewhat understand. So scripting in Horizon is sort of defaulting to a modular system so that it automatically can be used on multiple objects. For example, let's say that the script is simply
when object is grabbed by player

scale self to 2x2x2.

Then you go into your 5 bows and you use the dropdown on each one to attach them to GrowBow script.

Now when someone picks up any of the 5 bows, it will grow but the other ones won't. This means that each one of the bows will scale based on how many times it's been grabbed. No need to duplicate the script, it's just a matter of attaching the script to each device that will be using it. 

View solution in original post

8 REPLIES 8

teerez83
Protege

I'm fairly certain that this blocked intentionally. Otherwise you couldn't effectively calculate capacity in a world as it would be dynamic. The general method is to just copy/paste the object up to as many times as you need it. Hide all the ones you don't need initially and then use a script to grab them from a list and unhide/re-hide as needed.


@teerez83 wrote:

I'm fairly certain that this blocked intentionally. Otherwise you couldn't effectively calculate capacity in a world as it would be dynamic. The general method is to just copy/paste the object up to as many times as you need it. Hide all the ones you don't need initially and then use a script to grab them from a list and unhide/re-hide as needed.


I think I need to learn more about scripting/hiding 😅 

does that mean you can’t duplicate script along with the object? So I would have to manually re-script every bow I duplicated to get them to work?

Or if I erase other stuff in the world first will it work because there would be capacity open? 
just to be clear, I’m only trying to create more in build mode, not trying to make duplicating possible while playing.

Sopwyth
Explorer

I see how my initial comment might have been confusing. Not trying to use script to duplicate an object, but wanting to duplicate and object script and all included

teerez83
Protege

Ah ok. I think I somewhat understand. So scripting in Horizon is sort of defaulting to a modular system so that it automatically can be used on multiple objects. For example, let's say that the script is simply
when object is grabbed by player

scale self to 2x2x2.

Then you go into your 5 bows and you use the dropdown on each one to attach them to GrowBow script.

Now when someone picks up any of the 5 bows, it will grow but the other ones won't. This means that each one of the bows will scale based on how many times it's been grabbed. No need to duplicate the script, it's just a matter of attaching the script to each device that will be using it. 

ohhh ok I think I understand…. You don’t duplicate script, just objects. But you can attach multiple objects to the same script. So it’s a matter of going through and attaching new duplicated bows to the original script?

Another key thing to note is that when you set variables in the parent script. It will be the default where applicable, but when you attach a bow to that script, you can then manually change those values in the objects script properties. A very important exception is that objects cannot be defined by default. So for example, let's say you want to play a sound on each of the 5 bows when someone presses a button while holding a bow. You need a "BowSound" variable in the script but you cannot drop a pill into the script to make one sound object the default. Instead you need to go into each of the 5 bows and drop a sound object into the "BowSound" variable. This can either be 5 different sounds, or use the same sound on all 5 bows manually. There's a way to utilize a list and controller but that's a little more advanced.

There's also some cool behavior when you clone objects that are already tied to a script. In my sound example, if you pointed a bows BowSound variable to a sound object, when you clone that bow, it'll automatically keep the same reference to that existing sound object. Super useful to set up most of your script prior to cloning unless you explicitly need different settings on each bow and even then, change them afterwards.

Awesome, thank you!!!