# Making a Loading Screen

You may be used to making loading screens when using Unity's regular scene loading, but how can you do it for networked scenes? A good and simple solution is to use FishNet's Scene Processor to add *(or override)* functionality during when FishNet loads scenes.

{% stepper %}
{% step %}

#### Creating a loading screen UI

Let's start by adding a canvas with an image and some text to cover the screen and let the user know that the game is currently loading and not just frozen.

<figure><img src="/files/kybP7lS5laSnn1iiXTt3" alt=""><figcaption></figcaption></figure>

We will disable and enable this object when needed, and to prevent it getting destroyed, we will mark it as [DontDestroyOnLoad](https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html).
{% endstep %}

{% step %}

#### Adding a simple loading screen script

We can now write a really simple script and place it on our **Loading Screen** object.

This script will act as a singleton, as we will only have one loading screen in our game. To do this we will add a static reference to it and register it with the [NetworkManager](/docs/fishnet-building-blocks/components/managers/network-manager.md) in Start, or destroy it if an instance is already registered. We will hide the loading screen after this, so it doesn't block our game before we want it to.

{% code title="LoadingScreen.cs" lineNumbers="true" %}

```csharp
using FishNet;
using UnityEngine;

public class LoadingScreen : MonoBehaviour
{
    private void Start()
    {
        if (InstanceFinder.NetworkManager.HasInstance<LoadingScreen>())
        {
            Destroy(gameObject);
            return;
        }

        InstanceFinder.NetworkManager.RegisterInstance(this);
        DontDestroyOnLoad(gameObject);
        HideLoadingScreen();
    }

    public static void ShowLoadingScreen()
    {
        if (InstanceFinder.NetworkManager.TryGetInstance(out LoadingScreen loadingScreen))
            loadingScreen.gameObject.SetActive(true);
    }

    public static void HideLoadingScreen()
    {
        if (InstanceFinder.NetworkManager.TryGetInstance(out LoadingScreen loadingScreen))
            loadingScreen.gameObject.SetActive(false);
    }
}
```

{% endcode %}

We will also give it public static methods to show and hide the loading screen. We can call these whenever we want to, and we will call them from our scene processor.

{% hint style="info" %}
This example script uses FishNet's instance registering to handle the singleton reference, but you can use your own or any other instead if you prefer.
{% endhint %}
{% endstep %}

{% step %}

#### Creating a custom scene processor

Now let's create a script that will inherit from FishNet's [DefaultSceneProcessor](https://fish-networking.com/FishNet/api/api/FishNet.Managing.Scened.DefaultSceneProcessor.html) and add our extra functionality when loading a scene. After inheriting from **DefaultSceneProcessor**, simply override the [LoadStart](mailto:undefined) and [LoadEnd](mailto:undefined) methods, call the base method to retain the default functionality and then tell our loading screen to be shown and hidden.

{% code title="LoadingScreenSceneProcessor.cs" lineNumbers="true" %}

```csharp
using FishNet.Managing.Scened;

public class LoadingScreenSceneProcessor : DefaultSceneProcessor
{
    public override void LoadStart(LoadQueueData queueData)
    {
        base.LoadStart(queueData);
        LoadingScreen.ShowLoadingScreen();
    }

    public override void LoadEnd(LoadQueueData queueData)
    {
        base.LoadEnd(queueData);
        LoadingScreen.HideLoadingScreen();
    }
}
```

{% endcode %}
{% endstep %}

{% step %}

#### Add our scene processor to the NetworkManager

Now add the **LoadingScreenSceneProcessor** script we just created to your network manager game object. Also add the [SceneManager](/docs/fishnet-building-blocks/components/managers/scenemanager.md) component if it isn't there already. The SceneManager has a **Scene Processor** field which you need to drag your **LoadingScreenSceneProcessor** component into.

<figure><img src="/files/iKYaJqw56GluqAokFqea" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### Success!

With that all setup, your loading screen should work whenever FishNet loads new scenes.

<figure><img src="/files/7pMLDtjgtUfFoW7WJ12U" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fish-networking.gitbook.io/docs/tutorials/simple/making-a-loading-screen.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
