The Godot Community Forums are back up and running! Please read the the announcement post for important information on what happened. Thanks!

Problem with Resource Loader in C#

UnknownUserUnknownUser Posts: 0
edited September 13 in General Support

I'm having a problem where when the resources fully load. They load and get put into the scene but when the camera goes over any of the resources there is a spike of lag. This only occurs with resources that have other scenes inside of them. Such as
->Weapon Root
-->Model
-->Collision
-->Scene that contains smaller pieces

The above example lags when I pull up the weapon but it won't lag if I get rid of the other scene. I want to say this isn't the other scenes fault because no matter how small the scene is the game will always lag.

Here is the code that I use to load objects into the world

Error error = loader.Poll();
    switch (error)
            {
                case Error.FileEof:
                    PackedScene holder = loader.GetResource().Duplicate() as PackedScene;
                    loader.Dispose();
                    Node node = holder.Instance();
                    loader = null;
                    navigation.AddChild(node);
                    if (loadingPaths.Count == 0)
                    {
                        currentRoom = node;
                        loadingBar.Value = 100;
                        waitFrame = 30f;
                    }
                    else
                    {
                        loader = ResourceLoader.LoadInteractive(loadingPaths.Dequeue());
                    }
                    break;
                case Error.Ok:
                    float temp = (loader.GetStage() / (float)loader.GetStageCount()) * 100 / (float)(loadingPaths.Count + 1);
                    if (loaded < temp)
                        loaded = temp;
                    loadingBar.Value = loaded;
                    break;
                default:
                    loader = null;
                    GD.Print("Error");
                    break;
            }

Best Answer

  • TwistedTwiglegTwistedTwigleg Posts: 3,129
    Accepted Answer

    Welcome to the forums @Holo74!

    Does the scene you are loading use a material specific to that scene? If so, it could be the material and its shader causing the lag spike, as discussed in this GitHub issue. You can kinda work around it by having all of the materials quickly rendered in a single frame, so they are all cached and compiled as mentioned in this Godot Q&A post.

Answers

  • TwistedTwiglegTwistedTwigleg Posts: 3,129Admin
    Accepted Answer

    Welcome to the forums @Holo74!

    Does the scene you are loading use a material specific to that scene? If so, it could be the material and its shader causing the lag spike, as discussed in this GitHub issue. You can kinda work around it by having all of the materials quickly rendered in a single frame, so they are all cached and compiled as mentioned in this Godot Q&A post.

  • That makes a lot more scene. I poked around for a little bit and saw that it may have been that. Thank you for responding and sorry for being so late.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file