Forum Discussion
hopki37
12 years agoHonored Guest
Photon network + the oculus rift
I am finishing up with a very simple demo using the photon network for unity, the art is all done and most of the code if done but with a few small hiccups.
-The project
the teacher and the students of the class all put on there headsets. and the teacher controls the position of the students, taking them on a tour through an Egyptian queens tomb at Giza.
-the hiccup
To avoid more than one player, player controller, camera, ect. in the scean I have made the player a prefab to be called in and spawned at spawn spot. I would like to have it turn on the players player controller, camera, ect. upon spawning how ever
((MonoBehaviour)myPlayerGO.GetComponent("OVRCameraController")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("OVRGamepadController")).enabled = true;
Dose not seem to be working.
Is there some one on here who could help with some photon unity oculus integrator.
-The project
the teacher and the students of the class all put on there headsets. and the teacher controls the position of the students, taking them on a tour through an Egyptian queens tomb at Giza.
-the hiccup
To avoid more than one player, player controller, camera, ect. in the scean I have made the player a prefab to be called in and spawned at spawn spot. I would like to have it turn on the players player controller, camera, ect. upon spawning how ever
((MonoBehaviour)myPlayerGO.GetComponent("OVRCameraController")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("OVRGamepadController")).enabled = true;
Dose not seem to be working.
Is there some one on here who could help with some photon unity oculus integrator.
4 Replies
Replies have been turned off for this discussion
- drashHeroic ExplorerNot sure I could help you with the networking aspect of it, but I do have a couple of observations:
1) I believe that Oculus' OVRGamepadController is meant to be used as a helper component so that other scripts can query for the current state of the gamepad -- being placed on the player prefab itself is probably sub-optimal.
2) Why not leave everything active and enabled on the prefab? That way, when it is instantiated, it's all ready to go at the same time -- no need to enable specific components after instantiating. With the approach you are taking, you may run into problems where one prefab component's Update() assumes that another prefab component's Start() has already occurred -- and this may not be valid if you're enabling previously disabled components after spawning it.
Beyond that, it could help to have more specifics about what isn't working. - hopki37Honored GuestThat is some good advise and it might just work.
testing it now, but im getting an error
Error ----
Assets/NetworkManager.cs(122,17): error CS0103: The name `OVRPlayerController2' does not exist in the current context
code line---
OVRPlayerController2.SetActive(true);
Spawning code---
SpawnSpot mySpawnSpot = spawnSpots[ Random.Range (0, spawnSpots.Length) ];
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("OVRPlayerController2" +
"", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
Any thoughts as to how I might fix this. - artscilabsHonored GuestNot sure if you figured it out or not, but if you're going to use PhotonNetwork.Instantiate the prefab you want to instantiate needs to be in the root of the Assets/Resources folder.
I ran into a similar issue trying to turn on and off specific components for remote players. You can always write a script that holds a public reference to it and write a function you can call after its been instantiated.
--simple example--
NetworkPlayer.cs
public OVRPlayerController m_OVRPlayer;
public OVRDevice m_OVRDevice;
public void SetNeededActive()
{
m_OVRPlayer.enabled = true;
m_OVRDevice.enabled = true;
} - RatstacheHonored GuestHi there,
Intro
I've been using the Oculus Rift and PUN+ together for quite some time now. There are quite a few little problems that you'll run into when starting to tackle this problem. Some of them being: The ability to control another character, automatically use another characters OVRrig by default and kicking them off of it, as well as a tonnes of other subtleties that you have to weed out through testing.
Solution
Basically what you want to do is keep the prefab enabled in the resources folder but disable all the components that you want to be controlled only by the player who spawned the object. For example, you want the cameras to be viewable only by the player who spawned it so make sure each of the cameras are disabled in the prefab and enabled after spawning it on the network. Same thing goes for the OVRCameraRig script, and the audiolistener. If you have any other scripts or components that you want to be affected/accessible only locally make sure they start off as disabled and are enabled upon spawning. Also, make sure you have a PhotonView script attached to the prefab with an attached observed component
Execution
There are a few different ways of enabling these components safely to ensure they aren't enabled for everyone else. The most common way is enabling them in OnJoinedRoom. This is because that particular method is only run by the person who is currently joining the room. Another common way is to have a script attached to the OVRCameraRig Prefab that does initialization. The problem with this is because the prefab will be spawned in everyone elses scene that the Start method is run by everyone. You can do a quick check using if(photonView.isMine) and do all the enabling inside that if statement. One weird little subtlety is if you want to parent the prefab you've just spawned to something... Obviously you want it to parent in the current users scene as well as all the network users scenes, so this should be place outside that if statement OR if you are using the first method I discussed, should be placed in a separate initialization script attached to the object you're spawning.
Testing
One quick thing on testing, I've found that the best way to do testing is to build your project and launch the direct to rift version. Beside the window that pops up when using direct to rift, run your project in Unity. This way you can run two instances on the same machine and quickly switch between them to test. I know there is software that lets you run multiple unity instances but it's pretty finicky.
I'm sorry I didn't see this earlier, I definitely would have answered. If you have any questions or if anything is unclear at all don't hesitate to post!
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 7 months ago
- 5 months ago