Reputation: 2882
I have adapted Unity's 2d-extras for my own purpose, but the customized asset at sometime stopped to get updated.
Typical cycle is: I assign the attributes & flags in inspector, and I save it, I can see asset updated in editor mode, and I can see them working in game mode. But if I open the tile.asset
using a text editor, you see nothing is saved to the file!
// Example: WaterEntity.asset
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9d1514134bc4fbd41bb739b1b9a49231, type: 3}
m_Name: WaterEntity
m_EditorClassIdentifier:
m_DefaultSprite: {fileID: 0} // in editor but not updated
m_DefaultGameObject: {fileID: 0}
m_DefaultColliderType: 1
m_DefaultTileAttributes: 8
m_DefaultTileEntity: 16
m_TileAttributesContainer: 0
isEntity: 0 // in editor but not updated
isBindToObject: 0 // in editor but not updated
I had to manually edit the asset file but got tiresome. And for some resources I cannot do it - I cannot get file ID and manually add to it, for example. Is the change cached somewhere? How can I apply the changes? Note: right click and "reimport" doesn't work.
As you can see, in editor mode it's actually here.
I have the editor code as bellow:
public override void OnInspectorGUI()
{
tile.m_DefaultSprite = EditorGUILayout.ObjectField("Default Sprite", tile.m_DefaultSprite, typeof(Sprite), false);
tile.m_DefaultColliderType = (Tile.ColliderType)EditorGUILayout.EnumPopup("Default Collider", tile.m_DefaultColliderType);
// whatever
}
Upvotes: 1
Views: 2683
Reputation: 2174
You have to make sure that your EditorScript correctly calls EditorUtility.SetDirty
.
I generally always call it in my OnEnable() method of the editor script, since that is called as soon as you select the object in question and are shown the inspector window.
private YourClass classObject;
private void OnEnable()
{
classObject = (YourClass)target;
EditorUtility.SetDirty(classObject);
}
Upvotes: 2