Unity Tip : OnValidate and build exe
Added 2021-05-21 06:58:16 +0000 UTCTip for developers on Unity
The "OnValidate", method allowing operations following modification in the editor or launching of the game, does not always start at runtime in exe mode (it always starts, a priori, at runtime via unity).
Advice: make a sub-method and use it both in the "OnValidate" and in the "Awake". To prevent certain operations from being duplicated, add conditions. For example the initialization of a variable only if it is null.
Astuce pour les développeurs sur Unity
Le "OnValidate", méthode permettant des opérations suite à modification dans l'éditeur ou au lancement du jeu, ne se lance pas toujours à l'exécution en mode exe (il se lance toujours, à priori, en exécution via unity).
Conseil : faire une sous-méthode et l'utiliser aussi bien dans le "OnValidate" que dans le "Awake". Pour éviter que certaines opérations soient doublées, ajouter des conditions. Par exemple l'initialisation d'une variable que si elle est nulle.