SebLague / Solar-System

Simple solar system experiment

Home Page:https://www.youtube.com/watch?v=7axImc1sxa0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mesh Filter of Terrain Mesh is not set in Play Mode

HappyHippo98 opened this issue · 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

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.

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!

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