- Home /
Question by
lightnarcissus · Aug 29, 2016 at 07:01 PM ·
buildnon-monobehavior
Instantiating non MonoBehaviour C# script in build
I am using a non-MonoBehaviour C# script
namespace MyNamespace
{
public partial class MainForm
{
public void MyFunction()
{
//some code here which fires in EDITOR but never in BUILD
}
}
}
and I'm instantiating the MainForm object from a C# MonoBehaviour script
using MyNamespace;
public class MyScript : MonoBehaviour {
MainForm form;
void Awake()
{
form= new MainForm();
}
void Start()
{
form.MyFunction();
}
}
As mentioned above, the function only fires in editor and never in the build. Do I have to include the non-MonoBehaviour C# script somewhere like the Resources folder?
Comment
Answer by DiegoSLTS · Aug 29, 2016 at 11:47 PM
You don't have to do anything special with non-MonoBehaviour classes, they work like any other non-MonoBehaviour classes you can find in the Unity API. If the code compiles then it can be executed in the build, so you problem is somewhere else. Can you share the code that's not running? Also, add a Debug.Log line before and after calling form.MyFunction to make sure that part of the code is running at all.