Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by GabrielBucsan · Aug 16, 2016 at 05:14 AM · unity 5crashinspectorchangevalue

Unity crashes when I change values on inspector

Hi guys. I'm having a hard time trying to find my error on this and I'd like your help. Here's my problem:

I have a script (and it only happens with that specific script) that generates a terrain. I have an editor script that has a button "Generate" so that I can test it in the scene view. The problem is that I can generate this map once but every time the mesh is already created Unity crashes if I try to change any value in the inspector of the object. That's weird because I was not facing that problem before the last Unity update. I reinstalled Unity, I turned my PC off and the problem persists. And since Unity doesn't give any errors I imagined that the problem was some infinite loop that I had, but that's weird too because the code runs at least once, demonstrating that it doesn't have one.

Here is my terrain generation code:

using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEditor;

public class MapGeneratorInfinite : MonoBehaviour {

 public enum DrawQuality{VeryLow, Low, Medium, High}
 public DrawQuality drawQuality;

 public bool isTerrace;
 public float terraceDivision = 100;

 [HideInInspector]
 public float heightMultiplier;
 public AnimationCurve heightCurve;

 [HideInInspector]
 public int chunkSize;
 [HideInInspector]
 public int levelOfDetail;
 [HideInInspector]
 public float scale;

 public int octaves;
 [Range(0,1)]
 public float persistance;
 public float lacunarity;

 public int seed;
 public Vector2 offset;

 public TerrainType[] regions;

 public bool useFallout;
 public AnimationCurve falloutCurve;
 public bool invertFalloutCurve;
 public bool useCircularMap;
 public bool invertCircularMap;
 public bool generateRivers;
 [Range(0,1)]
 public float seaLevel;
 [Range(0,1)]
 public float spawnHeight;
 [Range(0,30)]
 public int numberOfRivers;
 public bool autoUpdate;

 public GameObject water;

 [HideInInspector]
 public VertexTile[,] tileMap;
 [HideInInspector]
 public float[,] noiseMap;
 [HideInInspector]
 public Color[] colourMap;
 float[,] falloutMap;
 float[,] circularMap;

 void Awake(){

     GenerateMap ();

 }
 
 public void GenerateMap(){

     if (drawQuality == DrawQuality.VeryLow) {

         chunkSize = 241;
         levelOfDetail = 1;
         scale = 240;
         heightMultiplier = 24;

         water.transform.localScale = new Vector3 (24, 0, 24);

     }else if (drawQuality == DrawQuality.Low) {

         chunkSize = 481;
         levelOfDetail = 2;
         scale = 480;
         heightMultiplier = 48;

         water.transform.localScale = new Vector3 (48, 0, 48);

     }else if (drawQuality == DrawQuality.Medium) {

         chunkSize = 961;
         levelOfDetail = 3;
         scale = 960;
         heightMultiplier = 96;

         water.transform.localScale = new Vector3 (96, 0, 96);

     }else if (drawQuality == DrawQuality.High) {

         chunkSize = 1921;
         levelOfDetail = 4;
         scale = 1920;
         heightMultiplier = 192;

         water.transform.localScale = new Vector3 (192, 0, 192);

     }
       
     water.transform.position = new Vector3(0, heightCurve.Evaluate (seaLevel) * heightMultiplier, 0);

     //Gera terreno
     noiseMap = Noise.GenerateNoiseMap (chunkSize, chunkSize, seed, scale, octaves, persistance, lacunarity, offset);

     //Aplica fallout map
     if (useFallout) {

         noiseMap = ApplyFalloutMap (noiseMap);

     }

     //Aplica circular map
     if (useCircularMap) {

         noiseMap = ApplyCircularMap (noiseMap);

     }

     //Aplica terrace map
     if (isTerrace) {

         noiseMap = ApplyTerraceMap (noiseMap, terraceDivision);

     }

     //Cria Tilemap
     tileMap = new VertexTile[noiseMap.GetLength(0), noiseMap.GetLength(0)];

     for (int y = 0; y < noiseMap.GetLength(0); y ++) {

         EditorUtility.DisplayProgressBar ("Generating tilemap: " + (y + 1), "Loading", (float)y / chunkSize);

         for (int x = 0; x < noiseMap.GetLength(0); x ++) {

             tileMap[x,y] = new VertexTile(noiseMap [x, y]);

         }
     }

     EditorUtility.ClearProgressBar ();

     //Pinta o mapa
     colourMap = new Color[chunkSize * chunkSize];

     for (int y = 0; y < chunkSize; y++) {
         for (int x = 0; x < chunkSize; x++) {

             float currentHeight = noiseMap [x, y];

             for (int i = 0; i < regions.Length; i++) {

                 if (currentHeight <= regions .height) {

                     colourMap [y * chunkSize + x] = regions .color;
                     break;

                 }

             }

         }
     }
     
     //Gera rios
     if (generateRivers) {
     
         for (int i = 0; i < numberOfRivers; i++) {

             EditorUtility.DisplayProgressBar ("Generating rivers: " + (i + 1), "Loading", (float)i / numberOfRivers);

             bool generated;

             AddRiver (out generated);

             if (!generated) {
         
                 i--;
         
             }

         }
         EditorUtility.ClearProgressBar ();
     }

     //Exibe resultado na tela
     MapDisplay display = FindObjectOfType<MapDisplay> ();

     display.DrawMesh (MeshGenerator.GenerateTerrainMeshInfinite (noiseMap, heightMultiplier, heightCurve, levelOfDetail), TextureGenerator.TextureFromColourMap (colourMap, chunkSize, chunkSize));

 }

 //Método chamado a cada alteração em variável
 void OnValidate(){

     if (octaves < 0) {

         octaves = 0;

     }

     if (lacunarity < 1) {

         lacunarity = 1;

     }

     if (scale < 1) {

         scale = 1;

     }

 }

 [System.Serializable]
 public struct TerrainType
 {

     public string name;
     public float height;
     public Color color;

 }

 public void AddRiver(out bool generated){

     generated = false;

     colourMap = RiverGenerator.GenerateRiver (noiseMap, seaLevel, spawnHeight, colourMap, out generated);

 }

 public float[,] ApplyFalloutMap(float[,] heightMap){

     float[,] returnMap = new float[heightMap.GetLength(0),heightMap.GetLength(0)];

     falloutMap = FalloutNoise.GenerateFalloutMap (heightMap.GetLength(0), falloutCurve, invertFalloutCurve);

     for (int y = 0; y < heightMap.GetLength(0); y++) {
         for (int x = 0; x < heightMap.GetLength(0); x++) {

             returnMap [x, y] = Mathf.Clamp01 (heightMap [x, y] - falloutMap[x,y]);

         }
     }

     return returnMap;

 }

 public float[,] ApplyCircularMap(float[,] heightMap){

     float[,] returnMap = new float[heightMap.GetLength(0),heightMap.GetLength(0)];

     circularMap = CircularNoise.GenerateCircularNoise (heightMap.GetLength(0), invertCircularMap);

     for (int y = 0; y < heightMap.GetLength(0); y++) {
         for (int x = 0; x < heightMap.GetLength(0); x++) {

             returnMap [x, y] = Mathf.Clamp01 (heightMap [x, y] - circularMap[x,y]);

         }
     }

     return returnMap;

 }

 public float[,] ApplyTerraceMap(float[,] heightMap, float division){

     float[,] returnMap = new float[heightMap.GetLength(0), heightMap.GetLength(0)];

     for (int y = 0; y < heightMap.GetLength(0); y++) {
         for (int x = 0; x < heightMap.GetLength(0); x++) {

             float tempHeight = 0;

             tempHeight = (Mathf.RoundToInt (heightMap [x, y] * division)) / division;
             tempHeight = Mathf.Clamp01 (tempHeight);

             returnMap [x, y] = tempHeight;

         }
     }

     return returnMap;

 }

}

And here is my Editor script:

using UnityEngine; using System.Collections; using UnityEditor;

[CustomEditor(typeof(MapGeneratorInfinite))] public class MapGeneratorInfiniteEditor : Editor {

 public override void OnInspectorGUI(){

     MapGeneratorInfinite mapGen = (MapGeneratorInfinite)target;

     if (DrawDefaultInspector()) {
         if (mapGen.autoUpdate) {

             mapGen.GenerateMap ();

         }
     }

     if (GUILayout.Button("Generate")) {

         mapGen.GenerateMap ();

     }

 }

}

I'd be glad if someone could spot the problem. If the other functions are required, please let me know. Thanks.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How can I fix/stop my Unity from crashing when using the Unity inspector? 0 Answers

How to make inspector value effect on play mode? 1 Answer

Unity.exe caused an Access Violation (Unity 5.6) 1 Answer

How to Force a Crash Dump When Unity Crashes in Windows 0 Answers

How to change array orders in the inspector 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges