Solar-System icon indicating copy to clipboard operation
Solar-System copied to clipboard

Mesh Filter of Terrain Mesh is not set in Play Mode

Open HappyHippo98 opened this issue 3 years ago • 4 comments

Hello together! I know, Issue#38 is pretty similar to my request, however I was not satisfied with the answer there. I tried to debug the problem, however I was not able to find the correct solution for myself.

In Edit Mode, I can generate different planets and I can edit them in terms of shape and shading (Picture 1). Sadly, if i press Play Mode, the terrain filter is not set in the inspector(picture 2). However, if i mark the terrain mesh within the inspector the shape of the terrain is drawn(picture 3). This means, that there is a terrain shape but the shading does not work correctly, right?

I tried to fix this but I did not get it right. Additionally, I am curious how to save a planet if i am satisfied with it?

I hope someone can help me :)

EditMode PlayMode_Unselected PlayMode_Selected

HappyHippo98 avatar Jul 29 '22 16:07 HappyHippo98

I have had this issue in the past. I do not remember how I fixed it but I can try to help.

You can try regenerating the mesh at runtime with HandleGameModeGeneration(), it's in the Celestial Body Generator of the planet. Another possible workaround is changing LOD to index 1, then 0 again. This can also be done through script, with the SetLOD() function. This might make the mesh show again.

I am curious how to save a planet if i am satisfied with it

Celestial body settings including seeds should not change on their own unless you hit randomise or obviously alter them yourself. You can note down a specific shape or shading seed for later use, alternatively make a copy of the celestial body settings and everything that goes along with it such as oceans, shading, shape etc.

Panicat avatar Jul 29 '22 18:07 Panicat

For all the other guys which suffer from the same error: @Panicat's second solution worked perfectly for me. I created a mini script which swaps between LOD1 and LOD0 of the planets terrain after the game starts.

public class UpdateMesh : MonoBehaviour{
[SerializeField] private CelestialBodyGenerator gen;
[SerializeField] private bool update;


// Update is called once per frame
void Update()
{
    if (update){
        gen.SetLOD(1);
        gen.SetLOD(0);
        update = false;
    }
}

}

However, I have to trigger the bool "update" per mouse click. Otherwise, the terrain will still not get generated.

Also, thanks for your advise about saving the planets!

HappyHippo98 avatar Jul 29 '22 18:07 HappyHippo98

You don't have to have it in Update(). You can do it in the Start() function, when the object that has the script is loaded.

If you have multiple planets you can make a loop that loops through all CelestialBodyGenerators and resets their LOD. Something like this:

    CelestialBodyGenerator[] generators; //an array for generators which will be used later

    void Start()
    {
        generators = FindObjectsOfType<CelestialBodyGenerator>(); //get the generators in the scene
        foreach (CelestialBodyGenerator gen in generators) //for every generator refresh the LOD
        {
            gen.SetLOD(1);
            gen.SetLOD(0);
        }
    }

Panicat avatar Jul 30 '22 12:07 Panicat

I think this happens because the Test Light field of the Planet Test component of the Test Gameobject of the Planet Scene is not assigned, preventing PlanetTest.cs Awake() from completing and grabbing CelestialBodyGenerator references in bodies, which prevent its Update() from setting the bodies LODs.

Since we don't want the test light to deactivate anyway (it hides the planet and the atmosphere), I recommand just commenting this line.

r0levrai avatar Sep 06 '24 10:09 r0levrai