Jump to content

Loading Screen not closing when using a custom controller/player


Thomas123
Go to solution Solved by Peter,

Recommended Posts

Just for documentation purposes if someone else has this problem. I could not find anything related in this forum. Hopefully someone of the team already in discord or another thread. I am linking both.

--------------------

For now I use Gaia without Sectr but with Gaia Streaming (it looks already faster btw.). Now I use a custom character as well. The character is spawned, the terrain under the character is loaded (using the terrain loader script). But the loading screen won't be disabled.

When I use a Gaia player, the loading screen is disabled. So I must have missed something. What is this? Why does the Gaia Loading screen does not disable with a custom character? 

I debugged the script (Gaia Loading Screen) and can see that only Start() and OnLoadProgressUpdated() are called. But not OnLoadProgressEnded() is never called with a custom controller. The gaia player does not seem to call anything related to the loading screen. So what am I missing?

 

------ References -----

More details in discord: https://discord.com/channels/423247963457060866/935350210291433572/1117839449259266190

And maybe here as well: 

 

Link to comment
Share on other sites

You can look at the Runtime side, is the player properly setup?
or you can use the function:
GaiaAPI:
          /// <summary>
         /// Sets up the player and camera with Gaia runtime systems
         /// </summary>
         /// <param name="player"></param>
         /// <param name="camera"></param>
         public static void SetRuntimePlayerAndCamera(GameObject player, Camera camera, bool closePhotoMode)

Link to comment
Share on other sites

Thank you @Meudes! That helped a lot!

To put everything together.

- There is a Gaia Script "Gaia/Scripts/API/GaiaAPI.cs"
- This script seems to be the API and has documentation included (the one Meudes refers to)
- I wrote a small script and added it to my player prefab. So when the player is spawned, it will set the needed Gaia settings. Gaia needs a reference to the camera AND the player.

I wrote script and attached it to my player prefab. It's called but the reference within the runetime won't be changed. Any ideas?

 

Bildschirmfoto-2023-06-14-um-08-54-53.pn

 

Quote

using UnityEngine;

 

public class SetGaiaReferences : MonoBehaviour

{

/// <summary>

/// Sets up the player and camera with Gaia runtime systems

/// </summary>

/// <param name="player"></param>

/// <param name="camera"></param>

/// <param name="closePhotoMode"></param>

// last parameter is unused, but needed for interface.

// see GaiaGlobal.FinalizeCameraObjectRuntime

 

// Start is called before the first frame update

void Start()

{

Debug.Log("Set Player References for Gaia Runtime");

 

//if (GameObject.FindWithTag("MainCamera") == null)

//{

// return;

//}

// already checked in API call

GameObject m_ScriptParent = transform.root.gameObject;

Camera m_camera = GameObject.FindWithTag("MainCamera").GetComponent<Camera>();

 

Gaia.GaiaAPI.SetRuntimePlayerAndCamera(m_ScriptParent, m_camera, true);

 

}

 

}

 

Edited by Thomas123
screenshot added
Link to comment
Share on other sites

Hi @Thomas123, I reviewed the loading screen script and I think there should be no difference whether that script is being used with a custom controller or a regular one, it should "not care" what player is currently in the scene.
You mentioned that you already started debugging the script, and found that "OnLoadProgressEnded" is never called in the script - could you please debug further and check why that is the case?

Normally this would be called from line 72 in GaiaLoadingScreen.cs when the load progress is equal or greater than 1. If this is not being reached it would mean that e.g. one of the terrains was not loaded in for example, and that keeps the loading screen alive. 

Link to comment
Share on other sites

18 hours ago, Bryan said:

Did you apply the character and is your character tag and camera tag set correctly 

 

I can only apply the prefab (not the instance) to the custom player. Thus I wrote the script above to set the instance in playmode on Start(). But this did not work. The Main Camera is fix and seems to work.

It does not make a difference if I set + apply the prefab (from the project folder, not the scene hierarchy) in the custom player.

- The player has the tag "Player" and is set to layer "Player".
- The MainCamera is set to tag "MainCamera" and layer "PostProcessing"

Thanks for your help.

Link to comment
Share on other sites

13 hours ago, Peter said:

Hi @Thomas123, I reviewed the loading screen script and I think there should be no difference whether that script is being used with a custom controller or a regular one, it should "not care" what player is currently in the scene.
You mentioned that you already started debugging the script, and found that "OnLoadProgressEnded" is never called in the script - could you please debug further and check why that is the case?

Normally this would be called from line 72 in GaiaLoadingScreen.cs when the load progress is equal or greater than 1. If this is not being reached it would mean that e.g. one of the terrains was not loaded in for example, and that keeps the loading screen alive. 

Thanks for your help.

I guess my explanation is not well formulated, sorry. I use the referenced script only on my custom player prefab. When I use the gaia player,  I do not add this script, because everything works as expected. The script is not needed (if it would do anything ;-)).

I think these parts are playing together:

1. Gaia: TerrainLoader.cs: Will handle terrain loading. When it's done, it will send the event "OnLoadProgressEnded()"

2. Gaia: GaiaLoadingScreen.cs: Will handle the progress of the loading (triggered by TerrainLoader) and will disable the screen, when TerrainLoader is finished (event OnLoadProgressEnded())

3. The player has to wait for the loaded terrain as well, so the player won't fall through the terrain. This is handled by ""RigidbodyWaitForTerrainLoad.cs". Adding this script + Rigidbody to my player prefab does not help the loading screen.

So I miss the part, what a custom player controller has to do with TerrainLoaderManager.cs. It should load the terrain independant. But maybe it is because it depends on the player location what terrains to load. So I assume, that the problem is that my script won't set the player instance / or the GaiaAPI does not work as expected / or Start() is too late

Link to comment
Share on other sites

What scripts do I have to add to a custom player, so it's recognized by gaia? It needs different ones as the original players have.

Link to comment
Share on other sites

  • Solution

Hi @Thomas123, I just realized I did not talk about your custom script and the Player Controller Setup in my reply, sorry about that! Here is some additional info:
 

  • When you instantiate your player yourself and then do the Gaia API call to set up the player and the camera, Gaia should add the player and camera to all the other systems in the scene, e.g. if you have Gaia water in the scene it will add the camera reference where required so that e.g. reflections or underwater effects are working. This is exactly the right thing to do when you create the player yourself during runtime.
  • In this case it is also correct that the reference to the "Main Player" in the Gaia Player object remains empty. This control is intended to be used when you have a custom player, but that is added during design time and is a permanent part of the scene. In that case you can put the character object into the "Main Player" slot and press the Apply button, which, under the hood, does the exact same thing as the Gaia API call to set up player and camera.
  • Both the terrain loader and the loading screen should not care or know about the player, they only look after the Terrain Loader script, and this script can be attached to anything, a camera, a character, a car, even an empty Game Object. It is also possible to have multiple terrain loader scripts running at the same time.
  • I would not focus on the player setup at the moment, but try to find out why the call to "OnLoadProgressEnded" never happens. I just looked at the script again and found something curious that might maybe relevant to your case:
    image.png

    The "OnLoadProgressEnded" function is subscribed to the wrong event in the Terrain Loader Manager, it would need to subscribe to 
    "TerrainLoaderManager.Instance.OnLoadProgressEnded" 
    of course.
    In theory this is a bug in Gaia, in practice this should not matter as the OnLoadProgressEnded function is already called from the LoadingScreen script itself before from line 72:

    image.png

    To further investigate this, can you please try the following:

    In GaiaLoadingScreen.cs can you please change lines 32 and 41 so that the OnLoadProgressEnded function is subscribed to the correct event, like so:

    image.png

    If that does not make any difference, can you please set a breakpoint at line 70 and investigate if the "progress" variable is being updated during runtime, and if yes, if it seems to stop at a certain point?

    image.png

    My guess is this variable never reaches the value of 1 for some reason, or is never updated at all which is why the loading screen never goes away. Finding out if my guess is right would be key to figure out what is going on.
  • Thanks 2
Link to comment
Share on other sites

Thanks a lot for your explanation and your solution. 

I just copied the Gaia script and put some logging outputs in. I did not see the wrong subscription. Correcting it, solved the problem. But now I do not understand why this makes a difference when using a custom controller instead of a Gaia controller.
"In theory this is a bug in Gaia, in practice this should not matter as the OnLoadProgressEnded function is already called from the LoadingScreen script itself before from line 72:". It's basically the same script. And using a Gaia controller will work with it. Anyway - now it works. Thanks again!

To put it together for someone else. If you use a custom controller / player:

  • you have to add the following components to your player prefab
    • TerrainLoader.cs
    • FloatingPointFix.cs (if used)
    • RigidbodyWaitForTerrainLoad.cs
  • you have to inform Gaia about your player and camera:
    • Gaia.GaiaAPI.SetRuntimePlayerAndCamera(PlayerObject, MainCamera, true);
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Tell a friend

    Love Canopy - Procedural Worlds? Tell a friend!
  • Need help?

    We work with some of the biggest brands in global gaming, automotive, technology, and government to create environments, games, simulations, and product launches for desktop, mobile, and VR.

    Our unique expertise and technology enable us to deliver solutions that look and run better at a fraction of the time and cost of a typical project.

    Check out some of our non-NDA work in the Gallery, and then Contact Us to accelerate your next project!

×
×
  • Create New...