- Home /
Does the function Update remains in the final build even if its only used for Assertions methods?
Like in this example from the Unity docs, if we compile this in the final build the Update function will be empty, or it will be removed as well? since its not being used.
using UnityEngine;
using UnityEngine.Assertions;
public class AssertionExampleClass : MonoBehaviour
{
public int health;
public GameObject go;
void Update()
{
// You expect the health never to be equal to zero
Assert.AreNotEqual(0, health);
// The referenced GameObject should be always (in every frame) be active
Assert.IsTrue(go.activeInHierarchy);
}
}
Comment
Best Answer
Answer by Bunny83 · Jul 17, 2018 at 10:21 AM
Yes it will stay in a build and furthermore it will still be executed. Unity does not strip unused or empty methods as it's still possible to invoke a method through SendMessage. If you want to get rid of the Update method in builds, use preprocessor conditionals
#if UNITY_EDITOR
void Update()
{
// You expect the health never to be equal to zero
Assert.AreNotEqual(0, health);
// The referenced GameObject should be always (in every frame) be active
Assert.IsTrue(go.activeInHierarchy);
}
#endif
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
c# - copy a function in another? 2 Answers
call function with same name + number 1 Answer
Why does my mouselook sensitivity change depending on resolution? (C#) 1 Answer