- Home /
Delegate bug, or intended behaviour?
So lets say you create a class and a method in that class.
using UnityEngine;
using System.Collections;
public class DelegateTest
{
public void Method ()
{
Debug.Log ("Test");
}
}
And then in another class you define a variable of that type and then assign the method, "Method" to a delegate in Start (), then call the method in the delegate in Update ()...
public class DelegateTest1 : MonoBehaviour {
delegate void Delegate1 ();
DelegateTest test1 = new DelegateTest ();
Delegate1 methodDelegate;
// Use this for initialization
void Start ()
{
methodDelegate = test1.Method;
}
// Update is called once per frame
void Update () {
methodDelegate ();
}
It works fine when you press play in Unity. "Test" gets outputted to the console. However, if you go back and edit your script whilst leaving Unity in play mode then go back to Unity. After it has finished recompiling, the delegate variable is cleared and will no longer output "test", but will throw a null reference exception instead.
Is this an intended behaviour? Or a bug?
Your answer

Follow this Question
Related Questions
Action delegate doesn't show in inspector. 1 Answer
Multiple classes delegates combining methods? 1 Answer
Interaction script 2 Answers
Editor Camera moving while rotating 0 Answers
My first time launching Unity and i have no text plz help 1 Answer