- Home /
Does a DLL work in an iOS build?
I made a sample project where I have a DLL that contains a class that creates a GameObject and adds a script component to this game object.
This is the code I'm packing into a DLL:
using UnityEngine;
public class DLLTest : MonoBehaviour {
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
public static void Initialize()
{
Debug.Log("INITIALIZE");
var go = new GameObject(typeof(DLLTest).FullName);
go.AddComponent<DLLTest>();
}
// Use this for initialization
void Start () {
Debug.Log("STARTING");
}
// Update is called once per frame
void Update () {
}
}
In the editor when I play the scene the game object is created and the Start method is executed. But when I build the project for the iOS platform, nothing happens. Am I doing something wrong? Can I really use a C# DLL in the iOS build?
Answer by Bunny83 · Dec 21, 2018 at 09:27 PM
It's hard to tell what exactly happens on your end. The pure fact that the class is in an assembly should be irrelevant as all your scripts are actually compiled into an assembly. When you build for IOs all your managed C# code is cross compiled into Objective C which is actually reviewed by Apply. Note that IOs is an AOT platform. So you can't have anything in your project that relies on dynamic code generation. Everything must by linked statically. Also stripping may cause issues at compile time. Make sure your class / assembly isn't stripped from your project. You could create a prefab with your class attached and place the prefab in a resources folder. That way Unity can not strip the class / assembly.
So the short answer is: yes, you can compile your classes into a seperate assembly as long as this assembly is part of your project (somewhere inside the assets folder) and not stripped. At the same time: no, on the device itself you can not use dynamically loaded dlls as this is forbidden by Apple since they can not review dynamically loaded code.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Build C# to dll for .NET 3.5 w/ VS 2017 0 Answers
Can I use a DLL in a iOS game? 1 Answer
Disable JIT compilation in the Editor (Enable Full-AOT mode) 0 Answers