Spectator View Setup - No NetworkDiscoveryWithAnchor objects

I am setting up Spectator View for a project that's under an NDA. This is my first time doing this, and I'm already running into some trouble regarding anchors.

On following the steps as outlined here:
one of the errors I get is as follows:

NullReferenceException: Object reference not set to an instance of an object SpectatorView.JoinSelectedSessionButton.Update () (at Assets/Addons/HolographicCameraRig/SV_UNET/Prefabs/Support/Scripts/UI/JoinSelectedSessionButton.cs:32)

Line 32 of JoinSelectedSessionButton.cs is
if (networkDiscovery.running && networkDiscovery.isClient)

The error exists because the static variable Instance of type NetworkDiscoveryWithAnchors is assigned null, as the starting code for that class did not find any objects that are of type NetworkDiscoveryWithAnchors. This debug output explains:

Expected exactly 1 SpectatorView.NetworkDiscoveryWithAnchors but found 0 UnityEngine.Debug:LogFormat(String, Object[]) SpectatorView.NetworkDiscoveryWithAnchors:get_Instance() (at Assets/Addons/HolographicCameraRig/SV_UNET/Scripts/NetworkDiscoveryWithAnchors.cs:33) SpectatorView.SpectatorViewManager:Update() (at Assets/Addons/HolographicCameraRig/Scripts/SpectatorViewManager.cs:298)

Right now in my scene I don't have any anchors. But before I add one into place, I want to make sure that upon adding one, this line
NetworkDiscoveryWithAnchors[] objects = FindObjectsOfType<NetworkDiscoveryWithAnchors>();
will return an array of length one.

I did try having the hologram I want to anchor to as a child of a game object with the NetworkDiscoveryWithAnchors script. That didn't work. I also tried making the hologram as a child of the UNetAnchorRoot game object that's part of the Sharing prefab.

What am I supposed to do? I feel like I don't need to do anything except just add an anchor to the scene (which I don't know how quite yet).


  • dbarrettdbarrett ✭✭✭

    So, the way that HoloLens does multiplayer is through the use of Anchors. The NetworkDiscoveryWithAnchors is a script that basically determines a lot of different things about its local state. Basically, it determines if its state needs to be a server and then kicks off that process or if it needs to be a client in which it starts that process.

    You have to have an anchor when developing a multiplayer game on HoloLens because that is how it basically starts the server. If you are the client it looks for the host's anchor and connects, otherwise it creates its own.

    Some starting advice, open the SharingWithUnet Scene, copy the entire hierarchy and paste it in a new scene. (So that you don't corrupt the original one). If you want to turn off the shooting bullets, go into the PlayerController.cs and comment out the Fire() method. This will give you the basic set up for a multiplayer scene and have all the scripts necessary for running your game as multiplayer. Take a look through it and figure out what each object does. There are some scripts that stay the same and others that have changed. Also take a look at the player and the netBullet prefabs as they are spawned at runtime. I'd also advise on taking a look at the basic Unity Multiplayer tutorials to learn more about how it works.

    AR Developer

  • edited April 9

    I'll take a look and find that hierarchy to experiment with. It's not a game, by the way. It's a business application. (Because of the NDA, I can't explain more of what it is)

  • This is really harder than it looks.

  • From the example scene you've described, I copied two GameObjects to my scene: Managers and HologramCollection. I deleted some objects because they didn't fit the purpose of the project.

    I still see the same error as described above. It's my impression that what I need to do is find a script called WorldAnchor (or ImportExportAnchorManager). I'll take a look more into this tomorrow.

  • dbarrettdbarrett ✭✭✭

    Game or business application, your app still has to follow the same flow as any other UNET multiplayer app. Developing multiplayer versus developing single player are two totally different development paths.

    AR Developer

  • I don't know what to do next at the moment, but there may be something that pops in my head later on. You can still follow up with me on it.

  • dbarrettdbarrett ✭✭✭

    I'd take a look at Commands and ClientRpc's in Unity. It will be the basics of how you "do stuff" over the server to affect the clients. There are other methods but, this is the most basic. Like I said, I highly recommend a tutorial on basic Unity multiplayer, you will learn a lot.

    AR Developer

  • Before I keep learning the multiplayer system and even attempt to use it in the project, there's something I need to ask.

    Why does the specification for the HoloLens spectator view does not say anything about Unity's multiplayer networking system at all? Isn't the toolkit itself able to register both HoloLens headsets, and display the Spectator View session on both and the server?

    In addition, do I need a full Spectator View rig and get the calibration data first before a Spectator View session really starts? I'm trying to understand fully about the Spectator View setup process (excuse me for changing topics).

  • dbarrettdbarrett ✭✭✭

    The toolkit is nothing more than helper scripts to access the data that is unique to the HoloLens, like Spatial mapping and anchors. It does more than that like give examples on how to use everything but, essentially that is all it does. It doesn't create its own multiplayer system, it only uses the one Unity has already. As far as spectator view goes, it is essentially a multiplayer experience with one of the HoloLens being mounted to a camera so that it is easier to demo an app to a multitude of people.

    AR Developer

  • Alright. In that case, I want to make sure; suppose that one HoloLens I have has the Visual Studio solution deployed by USB, where that one will be the Spectator View Rig HoloLens. All the other HoloLens headsets I want to connect with shall have the solution be deployed by Wi-Fi.

    Once I have the multiplayer system set up, will these two headsets, along with the Unity Compositor Interface and the Sharing Service server, start communicating with each other where the "Available Sessions" disappear and the anchored holograms are displayed in place?

    My internship ends on April 27th, so I really need to get it set up.

  • The hologram I'm trying to anchor into place has a World Anchor component, but I am still getting the error as above. I'm still reading the tutorials for multiplayer networking, but otherwise what components do I need so that the instance variable for SpectatorView.NetworkDiscoveryWithAnchors is not null?

    That's the reason why I am not seeing a session to select from the client HoloLens.

  • dbarrettdbarrett ✭✭✭

    Go into HoloToolKit -> SharingWithUnet -> open the scene and copy everything in it and paste it into your scene.

    AR Developer

  • Why copy everything from that sample scene and paste it into the scene I have? I only want to find the components I need. The sample scene has components and objects I don't want.

  • dbarrettdbarrett ✭✭✭
    edited April 18

    The only thing that is optional in that scene is basically the spatial mapping and the uiContainer object. The debug text is also optional but, I would leave that in for debugging purposes...

    AR Developer

  • dbarrettdbarrett ✭✭✭

    if you already have a Player prefab then switch it out with the one that is on the UNETSharingStage object.

    AR Developer

  • Two components I came across that I don't want from copying that scene over is the Player and the Bullet prefabs, because that's not what we're looking for in the project itself. This is one of the reasons why I am asking specifically what components I need in order for the static variable Instance of the NetworkDiscoveryWithAnchors class to not be null.

    Remember, this is not a video game. This is a business application, and under non-disclosure agreements, I am not allowed to explain what the project is, and what is some information about myself.

  • I do not have a Player prefab, although I am thinking of creating one where all it has is a camera component and a network identity component. The people that are using the HoloLens headsets to look at the hologram from where the Spectator View rig is projecting towards do not have meshes at all.

  • Now, would you please be so kind as to explain to me, in detail, what components I need for NetworkDiscoveryWithAnchors to be not null? That way, I don't create a mess in my setup.

  • dbarrettdbarrett ✭✭✭

    You have to have a player prefab to spawn yourself onto the "server." I think you should think of this more as a game and less as a business app. You can't change how the multiplayer system works just because you don't like how it works.

    And as for the Bullet prefab all you have to do is change out your player prefab and it will not spawn bullets anymore. (Or go into the PlayerController script and comment out the Fire() line) or if You don't like the red cube on the player's head? Turn off the mesh renderer on the player prefab.

    That scene is literally as bare bones as it can get as far as multiplayer goes. You need everything that is in that scene minus the ones I stated above. You don't have to copy over the Player and Bullet prefabs. You don't need the Bullet at all but, you have to have a Player game object of some kind otherwise how will you get onto the server.

    AR Developer

Sign In or Register to comment.