Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

287
Visualizações
ScriptableObject data modified from code in editor mode, but containing asset file not changed

I have a ScriptableObject reference in a MonoBehaviour class.

Modify its values with CustomEditor button.

Save It.

Values seems changed. Even selected ScriptableObject Inspector displays data modified.

But asset file on disk don't have any data. And there's no data available from code of any another MonoBehaviour instance.

Here is a code snippet used to save my ScriptableObject.

public TextAsset text;
[SerializeField]
//Thats My Scriptable Object
public PathFramesList pathFramesList;
[SerializeField]
public List<List<ICurveData>> frameDatasList = new List<List<ICurveData>>();
// Called By CustomEditor Button
public void ReadData()
{
    #region BlahBlahBlah generating some data to save

    var separator = new string[] { "%" };
    var framesUnparsedData = text.text.Split(separator, StringSplitOptions.None);
    foreach (var f in framesUnparsedData)
        frameDatasList.Add(ParseFrame(f));
    var result = new ICurveData[frameDatasList.Count][];
    for (int i = 0; i < frameDatasList.Count; i++)
        result[i] = frameDatasList[i].ToArray();

    #endregion

    #region Trying to save data

    pathFramesList.frameDatasList = result; // Set data to object
    EditorUtility.SetDirty(pathFramesList); // Even This didn't help
    AssetDatabase.SaveAssets(); // Looks it doesn't work
    AssetDatabase.Refresh(); // Hoped this will help, whatever it do

    #endregion

}

And that's my ScriptableObjectClass And Its CustomEditor

[CreateAssetMenu(fileName = "ParsedPathData", menuName = "Create Path Data Asset")]
[System.Serializable]
public class PathFramesList : ScriptableObject
{
    [SerializeField]
    public ICurveData[][] frameDatasList;
}

#if UNITY_EDITOR
[CustomEditor(typeof(PathFramesList))]
public class PathFramesListEditor : Editor
{
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        PathFramesList pathFrameList = (PathFramesList)target;
        if(pathFrameList.frameDatasList == null)
        {
            GUILayout.TextField("Frames Count is 0");
        }
        else
        {
            // It still has all data
            GUILayout.TextField("Frames Count is " + pathFrameList.frameDatasList.Length, 200);
        }
        if(GUILayout.Button("SaveAsset"))
        {
            // Tried to force saving with this) Didn't help
            
            EditorUtility.SetDirty(target);
            EditorUtility.SetDirty(serializedObject.targetObject);
            serializedObject.Update();
            serializedObject.ApplyModifiedProperties();
            AssetDatabase.SaveAssets();
        }
    }
}
#endif
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Ok.
Looks like scriptable objects files just can't store interface implementations examples.
Any else data was written to file well,
Correct me, please, if i'm wrong.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda