SebLague / Solar-System

Simple solar system experiment
https://www.youtube.com/watch?v=7axImc1sxa0
MIT License
1.15k stars 315 forks source link

How to randomise shape/shading at runtime? #43

Closed Panicat closed 2 years ago

Panicat commented 2 years ago

Even if the seed and everything changes, the planet doesn't change while playing. When the game stops the changes are applied. Is there any way to change such settings at runtime?

I need this for my project. Generally a way to instantiate randomised planets. The only way I could think of doing that is spawning one in then randomising the seeds? Thanks.

Delofon commented 2 years ago

Regenerate the mesh with HandleGameModeGeneration() call in CelestialBodyGenerator. Due to LOD shenanigans, the changes may not be visible at first but they will be applied.

Panicat commented 2 years ago

Regenerate the mesh with HandleGameModeGeneration() call in CelestialBodyGenerator. Due to LOD shenanigans, the changes may not be visible at first but they will be applied.

Thanks, I made the HandleGameModeGeneration() function public and called it from another script and also tried from inside the Update() of CelestialBodyGenerator...

...but even though the console says the mesh is generated I am unable to see the mesh. It simply isn't there? I don't know if it really takes that long to load but it appears to me like it isn't gonna happen. The Terrain Mesh game object is enabled and should be visible... (When I exit play mode it appears again) Any ideas?

Delofon commented 2 years ago

As I said,

Due to LOD shenanigans, the changes may not be visible at first but they will be applied.

I haven't tried fiddling around with a proper fix, but as a work around you can just fly away from the planet and then come back with the enter key. The changes should be visible after that.

P.S. It could not be LOD stuff altogether but it's the only thing that comes to my mind for now anyway ;p

Panicat commented 2 years ago

Hm, I had the ship disabled but even enabling it and going really far and back it's invisible. Collision still works.

I can get it to be visible by hitting V (triggering HandleGameModeGeneration() through the CelestialBodyGenerator Update function), and it appears at the lowest LOD setting. Basically a pyramid at that point. This only happens provided I haven't tried to call the function from another script, or I change the LOD setting to something else if I HAVE called it from another script. I guess it resets it and allows for it to be generated again? Not sure. Hopefully I'm making sense.

Delofon commented 2 years ago

Huh, I called the generation method from other script too (Ship to be exact) and I observed exactly the same behaviour as I would from the generator script itself. I especially could not get this really weird LOD behaviour that you had, and everything works fine for me and becomes visible if I manually change the LOD too. (first to 2 and then to 0) Also, have you changed the LOD handling before in one way or another?

Panicat commented 2 years ago

What exactly do you mean by LOD handling? Like alterring the code? If so then no, I don't know how most of the stuff in there works.

Delofon commented 2 years ago

This issue is really weird indeed. If manually setting the LOD via SetLOD() doesn't help, then I don't know what do next. (as I said in my case everything works fine)

Panicat commented 2 years ago

manually setting the LOD via SetLOD()

That seems to work nicely. Even for when calling from another script. I'll add it to the end of my randomising function and I should be good to go.

Thank you so much! Very much appreciated :) Nice that the code has so many potential ways to solve possible issues! Solved!