Is it possible to duplicate a scene object via code?
Hello! I'm in need of a bit of assistance. I'm trying to create a script where I can duplicate an existing sceneObject when I tap a collider.
In the script, at a minimum I would like to -
1. //@input sceneObject objectToBeSpawned //drag and drop in the inspector a reference to the sceneObject I want to instantiate
2. On tap event, instantiate a copy of objectToBeSpawned at a given transform in the scene.
So essentially, every time I tap, I can instantiate another copy of whatever sceneObject I reference in the script.
In addition to pointing me the the correct method in the API, a little help with the syntax would be super appreciated!
Thanks in advance!
N
It's good question I am not sure on the specific method if even possbile to manipulate like what kinda object?
like a cube you can do with meshbuilder..its has examples of code so not going to help with syntax as its well documented already
https://lensstudio.snapchat.com/api/classes/MeshBuilder/
I was thinking maybe you could use the procedurla method https://lensstudio.snapchat.com/api/classes/RenderObjectProvider/
their is a link in the featured on how to use procedual its very cool
my concern would be memory performance hit and you lense not been submited.
another route might be
to hide the objects then when the user taps incrementally enable each one, you could set the object to look at the camera so its feels more like what your trying to achieve.
Hi art Nelson,
Here's an example script that might help. I tested it with the "Touch Started" event to create a copy of objectToBeSpawned on touch start.
Note that after copying an object, the new object doesn't get fully initialized right away, so you can't immediately make changes to it. That's why I repositioned the source object before making a copy, and restored its original position afterwards.
Hope this works for you! Let me know if you have any additional questions.
Jacob, at what point does the copied object get fully initialized?
Hey Robert,
The sample code I gave is actually pretty outdated, I would now recommend using Prefabs instead.
Sample code for doing this with a prefab:
Note that the parent object is optional in this case, since if null is passed in the object will spawn with no parent.