yeah, I’ve picked up the key part of the code, the ObjectField “noteProto” is reset when playing, and the noteProto is just a prefab Object with nothing special.
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
[CustomEditor(typeof(NoteSpawner))]
public class NoteSpawnerEditor : Editor
{
NoteSpawner spawner;
GameObject noteProto;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnEnable()
{
spawner = (NoteSpawner)target;
}
public override void OnInspectorGUI()
{
noteProto = (GameObject)EditorGUILayout.ObjectField("Note proto", noteProto, typeof(GameObject), false);
if (noteProto != null)
spawner.noteProto = noteProto;
}
}
This will let you assign null to spawner.noteProto, for example if you want to clear the field.
The original problem is that the editor script’s noteProto starts null. You could always set “noteProto = spawner.noteProto” in OnEnable(), but it’s probably better to omit it entirely.
Why TextureBaker.fogBakerMaterial goes to none when building the project or pressing “play” ?
The other 3 toggle variable keeps state, so only this material objct is reseted.
When Unity switches to play mode, it serializes your window, destroys it, and creates a new window with the serialized data. Only public fields, and private fields marked [SerializeField], are serialized. Everything else is reset to their default values. In addition, scene objects will be different in play mode because Unity serializes the scene and creates it new in play mode. So if your editor window has a reference to something in the scene, that reference will no longer be valid in play mode.
that material is a material that exists in my project, outside. And it+s a public static material. So given your comments it should work.
anyway I tried putting Serialiable and SerializeField, but it doesn’t work.
Can you post more code? What’s TextureBaker? Could another part of the script be assigning a value to TextureBaker.forBakerMaterial that is no longer valid? Also make sure to read through the Unity Serialization link above. It probably contains an answer to your question. Or check this post and keep a reference to the material’s instance ID.
I don’t know how to solve this from ui bulder, when starting playmode the values of the cmaps are reset, I don’t know if it’s an error in how I’m building the object or it’s a RuleTile error that can’t be used (I don’t think so), I’m using the unity tilemap2d package ruletile.