3
\$\begingroup\$

I had to make a change in the existing Universal Rendering Pipeline's ShadowCaster2D.cs to suit my needs. But every time I reload the project, the file gets reset. How do I prevent this?

The file that I need to keep is found in the following path:

(Unity Project path)\Library\PackageCache\com.unity.render-pipelines.universal@7.1.7\Runtime\2D\ShadowCaster2D.cs
\$\endgroup\$
1
  • \$\begingroup\$ +1 same problem, not sure there is much you can do, other than making your own package using the one you overwrite as a base. \$\endgroup\$ – Benjamin Danger Johnson Oct 4 '20 at 11:02
1
\$\begingroup\$

TLDR: following this unity forum thread, I just followed what polemical said which was to

in Project window, right-click the package, select "Show in Explorer". Then copy that package to another folder outside the project structure, then in Package Manager click the + and click "Add package from disk" and browse to the package.json of your copy - whatever changes to that won't be overwritten.

I tried to wrap my head around creating a script to modify the script but I'm a bit short on time. For now, this is the answer as also suggested by Benjamin.

If there's a better solution, I can mark that as an answer.


update 1: Since we're using a repository to handle the code, selecting the custom unity package locally is not advisable as Unity will crash upon startup because it can't locate the file in someone else's computer. to fix this, we had to create a repository that each one of us can access. Remove the local unity package and add the custom package using git url. the problem will be fixed

\$\endgroup\$
0
\$\begingroup\$

For some reason I can't comment so I'm going to have to answer instead. One option (I'm not sure it will work) is to modify the file in the package cache. I believe that unless you clear it, unity will pull the files from there each refresh. Another option is to create a script that runs on project reload and overwrites the file with the version you want.

Possible ways to receive callbacks

I haven't tested these and I'm not sure if they will work, but I hope they'll be helpful to you.

  • EditorApplication.playModeStateChanged
  • IPreprocessBuildWithReport
  • AssetsModifiedProcessor
  • UnityEditor.Build namespace

You mentioned the project reloading, so EditorApplication.projectChanged might be of help to you as well. These links https://answers.unity.com/questions/704066/callback-before-unity-reloads-editor-assemblies.html https://docs.unity3d.com/ScriptReference/Callbacks.DidReloadScripts.html might also provide you with enough information to solve your problem.

As a last resort, you could create your own copy of ShadowCaster2D and use that behaviour instead of the default one

\$\endgroup\$
3
  • \$\begingroup\$ I could send my team the modified package file but I was hoping to automate it. Would it be okay for you to show us an example on how to do it via script? I'm looking over the net and can't find a function that listens or gets called "after package reload". update: tried to modify the package file in `%appdata%\Local\Unity\cache\npm\packages.unity.com` but it still reverts back to its original file \$\endgroup\$ – CraftedGaming Oct 4 '20 at 15:12
  • \$\begingroup\$ I have updated my answer, I hope it solves your problem. Good luck! \$\endgroup\$ – Rowan Radosav - McRae Oct 6 '20 at 2:14
  • \$\begingroup\$ update: I made a copy of the ShadowCaster2D first but realized that some of the classes that are set to internal classes that this script uses is locked within a particular namespace. So I can't go for that option. I'm still looking into the script that can rewrite the code on project load \$\endgroup\$ – CraftedGaming Oct 8 '20 at 12:47
0
\$\begingroup\$

Don't edit the package in the Library, copy it to YourProject/Packages instead. The folder inside the Library can and will be overwritten at any time. The intended place for packages you don't want downloaded is YourProject/Packages.

\$\endgroup\$
1
  • \$\begingroup\$ I tried this but this file also gets reset after restarting Unity Editor \$\endgroup\$ – CraftedGaming Oct 8 '20 at 10:15

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.