2
\$\begingroup\$

Context:

I'm working with Unity using Git and we have .gitignore setup so that we could create "_local" folder anywhere in Assets and it won't be commited. It makes for kind of a Debug/Backup folder, where I can put any of textures I want to check or any script I want to test in Unity, but keep it locally.


Problem:

That unfortunately causes problems. After referencing many local files I decide to commit the project, so I make all the references pointing files that will be commited. Sometimes though I don't notice one wrong reference and I commit the project which causes errors on collaborators' devices.


Idea:

I came up with an idea that I could write a script which goes through every reference and if any of them points to a local file it should generate a warning or error. All that would happen after saving the project.


But can it be done?

Is there a way to find all the references and call the script once the project is saved?

\$\endgroup\$
1
\$\begingroup\$

Yes, it can be done:

https://docs.unity3d.com/ScriptReference/AssetModificationProcessor.html

https://docs.unity3d.com/ScriptReference/AssetModificationProcessor.OnWillSaveAssets.html

Example of usage:

using UnityEngine;
using UnityEditor;
using System.Collections;

public class FileModificationWarning : SaveAssetsProcessor
{
    static string[] OnWillSaveAssets(string[] paths)
    {
        Debug.Log("OnWillSaveAssets");
        foreach (string path in paths)
            Debug.Log(path);
        return paths;
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.