I’m working on a project with GoogleVR but I have a problem, when I run the app from the Unity editor the objects are created correctly but when I build it and run it on a cell phone with android it does not show me anything. This is the code to instantiate that I am implementing:
GameObject sphereP = Resources.Load ("PrefabsTest/Sphere", typeof (GameObject)) as GameObject;
sphere = Instantiate (sphereP.gameObject, transform.position, transform.rotation) as GameObject;
The name of my prefab is Sphere and the full path it is in is:
As I said before, in the unity editor it works correctly but at the moment of exporting it to a cell phone it does not show me anything, I have tried in several ways like to load the prefabs with public variables and then instantiate them and nothing works. I’m using unity 2018.1.1f1 and in the virtual reality SDKs i tried with cardboard and oculus.
I appreciate any help, thanks
Okay, I had exactly the same issue as you described. In my game, there were 3 prefabs. They spawn after a trigger is activated. Now, in editor when the trigger is triggered, those 3 prefabs mentioned, do in fact spawn and I can see them and interact with them. Now on the other hand when I built the APK and ran it on the device, those 3 prefabs were no where to be seen. WEIRD. I went the extra mile by checking if the loaded GameObjects are null when the game tries to spawn. Nop, nothing. Apparently they were working.
Well, The issue was with the physics. You see, I found that the prefabs were spawning INTO the ground and not on the surface, the reason why they showed up correctly on the editor was because they glitched onto the surface. On the android, weirdly, they were glitching BELOW the ground and fell of off the world.
I realize that this might not be the case for everyone. In that way I recommend to make another simple prefab with nothing in it. Like a sphere. Make it a prefab, put it into “Resources” folder and try to spawn it in the world so you should definitely see it. It’s unlikely that Unity would not do something without giving at least some sort of error message.