Byte code striptease

We all know about Managed Code stripping and that we have to manually mark code to not be stripped if that code is not referenced (called by reflections for example).

We can use the link.xml file to do that but there also is the Preserve Attibute. Using it we can mark methods (or classes) right inside our code.

Code Example:

// Let's keep the whole class
[Preserve]
public class YourClass
{
    static void SomethingThatIsCalledByReflection()
    {
        Debug.Log("I am still here!");
    }
}

// Or just a method.
public class YourClass
{
    [Preserve]
    static void SomethingThatIsCalledByReflection()
    {
        Debug.Log("I am still here!");
    }
}

Link: https://docs.unity3d.com/ScriptReference/Scripting.PreserveAttribute.html

Asset Recommendations

Here are some assets that may be useful to you. If you get one of them then some of the money will go towards funding this project. Thank you.

Disclosure: This text may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we have recommended. While clicking these links won't cost you any money, they will help fund this project! The links are created by Unity and Partnerize (Unity's affiliate partner).