04-27-2022 12:37 PM
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.
Solved! Go to Solution.
04-27-2022 02:37 PM
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.
04-27-2022 12:49 PM
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.
04-27-2022 02:17 PM
@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.
04-27-2022 02:23 PM
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
04-27-2022 02:37 PM
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.
04-27-2022 02:42 PM
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?
04-27-2022 02:43 PM
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.
04-27-2022 02:45 PM
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.
04-27-2022 02:49 PM
Awesome, thank you!!!