Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesh Filter of Terrain Mesh is not set in Play Mode #50

Open
HappyHippo98 opened this issue Jul 29, 2022 · 4 comments
Open

Mesh Filter of Terrain Mesh is not set in Play Mode #50

HappyHippo98 opened this issue Jul 29, 2022 · 4 comments

Comments

@HappyHippo98
Copy link

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

@Panicat
Copy link

Panicat commented Jul 29, 2022

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.

@HappyHippo98
Copy link
Author

HappyHippo98 commented Jul 29, 2022

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!

@Panicat
Copy link

Panicat commented Jul 30, 2022

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

@r0levrai
Copy link

r0levrai commented Sep 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants