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;
}