简体   繁体   中英

Unity editor conflicts with prefabs

So I'm working this hexagonal grid system for buildings in Unity. I made a 2d boolean array to set which area of the grid, the building will occupy. I have made a custom editor so I can edit it. It all works perfectly until I set it to a prefab. Then the grid that sets the area just resets. Is there any way I can fix this issue?

PS Weird this is when I set a slider in the same script. Unity had no problem remembering the slider's data. But changing it in the prefab caused it to reset

I'm using Unity version 2018.3.0f2

Custom editor scripts have the habit of loosing all their data upon play, instantiate or build. It is up to you to save the data upon edit and deserialize it back into the interface upon viewing. It is much easier to use custom [system.serializable] classes with [serializeField] in the declaration. a List of buildingRows classes, consisting of a list of a buildings classes would do fine in your case. It just does not look as pretty as you might like.

a neat workaround would be to use a [mutiline] string text inputfield in the inspector. buildings could be either the character "o" or "x" for example. When split on newlines this is essentially a 2D array of chars. Like this:

o o o o x o o o o o 
o x o o x x o o o x 
o o o o o x o x x x 
o o o x o o o o o o 
o o o x o o o x o o 
o o o x o o o x o o 
o o o x o o o x o o 
x x x x o o o x o o 
x x x o o o o x o o 
o o o o o o o o o o 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM