I am modifying the Unity Physics package; I am adding some custom functions in ConvexConvexDistanceQueries as well as referencing some code in from outside the package in the Assets folder. However, I get errors referencing code outside the package and I can’t drag stuff in the package folder (though I can modify existing scripts). How do I solve this? What is the best strategy to modify a package?
Thank you for your response! How do you copy it (from what source)? Can this be done in the finder? Can I just drag and drop into Unity? Thanks a lot for your help.
You can find original readonly package from YourProject/Library/PackageCache. Simply copy it to YourProject/Packages. Then re-open unity. After that, you can modify pacakge’s source code. (don’t forget change file write permission)
However, this is probably a bad idea, as the idea of packages is that they can be updated independently of your project.
A better or more SOLID way might be to inherit the particular class you want to modify, and then override or wrap the methods you are interacting with.
There is also a bit hacky way to extend any package (even Unity-provided) with access to its internals without modifying the package itself.
Create your own package as usual (e.g. create new directory in /Packages folder with package.json file)
Add .asmref file that references existing package (e.g. Unity.Collections)
Extend any class package using internal access:
In my example, access NativeList<int>.m_ListData even though it is marked with internal keyword.
using System.Collections;
using System.Collections.Generic;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine;
namespace Unity.Collections
{
public static class NativeListExtensions
{
public static unsafe UnsafeList* StealUnsafeList(this ref NativeList<int> list)
{
return list.m_ListData;
}
}
}
We do appreciate when some post are helpful to others. But please do not necro three years old threads in future just like that, not adding anything meaningful to the conversation. You can use like button, to say thank you to the poster instead.