Work Around not working

I have implemented the work around exactly as shown in the video. When I do a Debug.Log of the name it even shows that it has changed. However, it the editor, the error is still occurring, and the dialogue is becoming a child of a dialogue node asset database.

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

namespace RPG.Dialogue.Editor
{
    public class DialogueModificationProcessor : UnityEditor.AssetModificationProcessor
    {
        private static AssetMoveResult OnWillMoveAsset(string sourcePath, string destinationPath)
        {

            //Check if asset moved/renamed is a dialogue scriptable object.
            Dialogue dialogue = AssetDatabase.LoadMainAssetAtPath(sourcePath) as Dialogue;

            if(dialogue == null)
            {
                return AssetMoveResult.DidNotMove;
            }

            //Check if object was moved to a new folder.
            if(Path.GetDirectoryName(sourcePath) != Path.GetDirectoryName(destinationPath))
            {
                return AssetMoveResult.DidNotMove;
            }


            Debug.Log(dialogue.GetType());
            Debug.Log(dialogue.name);
            // Object is a Dialogue and is renamed.
            dialogue.name = Path.GetFileNameWithoutExtension(destinationPath); 

            
            Debug.Log(dialogue.GetType());
            Debug.Log(dialogue.name);
            Debug.Log(dialogue.GetRootNode().name);

            return AssetMoveResult.DidNotMove;
        }
    }
}


image
image
image

Hmmm… I’m not at all sure what’s happening here… I took the code from your paste and replaced my own script with it, and it performed as expected. I’m going to tag @sampattuzzi in on this to see if he has any ideas.

Unity version specific problem maybe?

Possibly. Unfortunately, this bug is something that Unity has been aware of for a very long time and not taken any apparent interest in fixing.

For now, you might be in a position that you need to do some planning in advance. The one time you can be assured Unity won’t rearrange the file structure is when you first create and name the file. (It can’t, because we don’t put the DialogueNode in until after it’s been given a name.)

@Yitzchak_Cohen are you sure the code compiled without errors? Sometimes worth restarting the editor.

@sampattuzzi yes I have restarted the editor several times, and triple checked the code is saved and compiling with no errors. The console even shows everything being renamed correctly.

It just seems like after my Dialogue Modification Processor finishes, unity’s going back and messing it up again.

In the log you attached it doesn’t look like your asset name is changing. Any idea why this is?

Oh I just noticed that now that you pointed it out. No, that’s strange, why isn’t it changing names?

dialogue.name = Path.GetFileNameWithoutExtension(destinationPath);

should happen there.

I tested it again, at least some times it is showing the new name. I added in a debug to print: GetFileNameWithoutExtension(destinationPath)

image

I actually replaced my own copy of the script with Yitzchak’s, and it’s working perfectly in my repo.

I was concerned that an error elsewhere might mean the code isn’t running.

1 Like

Maybe you can package and send us the project https://gdev.tv/projectupload

Uploaded my current version of the project.

Downloaded the project and got the reported result… despite the script being correct (I even swapped the original script from the course repo), the dialogue rename resulted in the bug.

What I can’t seem to see is why. The next step back in the chain is to go through and double check the creation of the nested scriptable object in the first place… tracing through this now to see if I can figure this out.

To be honest, I do not know what is going on. Everything in your code to store the dialoguenodes looks correct.

Did you run my project in a different version of Unity? I was wondering if that was affecting it.

No, it was the same version. I’ll recast it to a higher version when I get home from work. I’m still thinking there’s just like one thing I’m missing in the Dialogue.cs, but an hour of flow tracing and I couldn’t find it.

Privacy & Terms