Profile image

Draw Distance Help

92.8k MisterT  5.5 years ago

Hi all,

I'm making a map, and I wanted to increase the terrain draw distance, but it can only go to 2000.

So I used a script :

using UnityEngine;

[ExecuteInEditMode]
public class BasemapDistanceSet : MonoBehaviour
{
public float BasemapDistance = 20000;
private Terrain terrain;

void OnEnable () 
{
    terrain = GetComponent<Terrain> ();
    #if UNITY_EDITOR
    UnityEditor.EditorApplication.update += Set;
    #endif
}
void OnDisable()
{
    UnityEditor.EditorApplication.update -= Set;
}

#if !UNITY_EDITOR
void Update () 
{
Set
}
#endif

void Set () 
{
    if (terrain == null)
        terrain = GetComponent<Terrain> ();
    else if (terrain.basemapDistance != BasemapDistance)
        terrain.basemapDistance = BasemapDistance;
}

}

In Unity scene it works, but when it try to save mod, it says that there are compiler errors. Does anyone have the solution?

Fixed!

  • Log in to leave a comment
  • Profile image

    @MisterT thank you very much 😉😉😉

    5.4 years ago
  • Profile image
    92.8k MisterT

    @mikoyanster I think it's just because you have to write it step by step, and select the directoriy inside the console. I made a tutorial at the end of this post.

    +1 5.4 years ago
  • Profile image

    @MisterT Hi again, i´m trying use in the console, but gave me this message... "Command terrain not found" can you help me?

    5.4 years ago
  • Profile image
    92.8k MisterT

    @mikoyanster Idk, it would be great !

    5.5 years ago
  • Profile image

    @MisterT it´s great!!! but would there be any way for the change to be automatic when loading the map?

    5.5 years ago
  • Profile image
    92.8k MisterT

    Problem solved ! Just open the console in game, and type :

    Terrain.basemapDistance 20000

    Now it looks beautiful !

    @Gestour
    @mikoyanster
    @MOPCKOEDNISHE
    @DuckMint
    @Tully2001

    +1 5.5 years ago
  • Profile image

    This problem i had got un several experiments but i dont find a valid solution :-(

    5.5 years ago
  • Profile image
    92.8k MisterT

    @Gestour
    @mikoyanster
    @MOPCKOEDNISHE
    @DuckMint
    @Tully2001

    5.5 years ago
  • Profile image
    92.8k MisterT

    @WNP78 I tried to add (), no errors in the console, but still doesn't want to save the mod.

    5.5 years ago
  • Profile image
    92.8k MisterT

    @WNP78 @MOPCKOEDNISHE Thanks for your answers, I'm making a big map based on geographical data. I imported heightmap, and there is only one big photo texture (8000*8000). I just wanted to make it less blurry when I move away from the ground. The problem is I am a beginner on unity.

    5.5 years ago
  • Profile image

    If i correct understand you, you want enable or disable terrain in dependence by distance? It is unusual way. But i think that the draw distance depend from Rendering range of camera. If you want to disable game camera and use your own camera, then write script:

    public GameObject My_Own_Camera_gameobj;
    Camera My_Own_Camera;
    float my_Rendering_Range = 50000f;
    
    void Update()
    {
    
    if(!ServiceProvider.Instance.GameState.IsInDesigner)
        {
            ServiceProvider.Instance.GameCamera.SetMainCameraEnabled (false);
            My_Own_Camera = My_Own_Camera_gameobj.GetComponent<Camera> ();
            My_Own_Camera.farClipPlane = my_Rendering_Range;
            My_Own_Camera_gameobj.SetActive (true);
    
        }
    
    }
    
    +1 5.5 years ago
  • Profile image
    Dev WNP78

    Firstly, if it doesn't let you set above that level in the inspector, it probably won't let you via a script. Secondly, you're using what's called preprocessor directives. These are the lines that start with#. The #if command used (#if !UNITY_EDITOR basically means "anything inside this block should only be included if UNITY_EDITOR is not defined (the ! means "not" or "inverse"), which therefore means it will only be included when building for the game and not the editor). So the code in update doesn't get run (or even compiled) in the editor, which is why you don't get an error in the editor. However when it is compiled for leaving the editor, there is an error because you missed the empty brackets after Set (you always need brackets to execute a method, even if there are no parameters). It does seem like a strange and overcomplicated way of implementing it though, I'm not sure why it needs to be different in the editor and the game.

    +1 5.5 years ago
  • Profile image

    Wow it would be great if the draw distance was twice as far in the regular game.

    5.5 years ago
  • Profile image
    92.8k MisterT

    @Gestour
    @mikoyanster
    @MOPCKOEDNISHE
    @DuckMint
    @Tully2001

    5.5 years ago