Change prefab on plane dynamically

Hello, I am creating an app with two scenes. The first scene has a list of items and second is an AR scene. On selecting an item in the list I want to load the second scene and place the corresponding 3d object. I am using AR Foundation Sample Script and able to place a prefab which is the same regardless of which item is selected in the previous scene. Please advise how to dynamically change the prefab, depending on the item selected in the previous scene. PS: I know a singleton can be used get it working, but trying to avoid it. Thanks.

I would recommend creating a list of the prefabs that you want to create, in some kind of script that can hold references to prefabs, and then store the reference once they select it (or store a number of the index relative to the pre-determined list if you like) and when you move scenes, you’ll want to make use of Anchors to attach them to places on planes if need be, but the “same” end prefab will be one that finds the script/component that holds the selected prefab, and then instantiates said prefab into the new scene.

@WyattBUnity Thank you for the reply. I have a SceneManager script for switching scenes. Would you know how to get a reference to XR Origin object( which Place on plane script is attached to) in Scene Manager script(or any script)? Once I get a reference I will be able to set the prefab on Place on plane script.

There may be a better way, but GetComponent<XROrigin>() will work, but be mindful that it would be bad practice to call this line every frame, so storing a reference after calling this line would be better.

2 Likes