How to either copy an asset or instantiate directly from path
Ok so this is a bit of a weird request. I'm looking to have object A spawn object B right before it gets destroyed. I have succeeding is copying all the values to a safe space where object A can be destroyed before object B is instantiated. However, I can't copy the Asset.ObjectPrefab object that was declared in object A's script.
Is there any way for me to copy the object into a safe place where I know the reference wont be lost after object A is destroyed? I don't see a copy function like sceneobjects have.
The other option is that I have notices the name value stored in an ObjectPrefab instance is the pathname to the asset in the editor. Is there any way to instantiate a new sceneobject directly from a path instead?
Hi Patrick,
How did the answer you received from our engineers work out? We'd love to get an update!
For everyone else:
Asset.ObjectPrefab is in fact an asset that is stored in your Resources once you've added/created it. It's not an object itself and can only be removed from your project Resources. As I understand, while destroying object A you are loosing reference to this asset (that you want to use to instantiate object B). To avoid this you can declare reference as globally available variable in separate script:
Then you can reuse it in other scripts like this:
Just make sure this script has been already triggered before trying to use its variable (for example set script event to Initialize). More info on this is available in https://lensstudio.snapchat.com/guides/scripting/scripting-overview/