Do Static Class in Unity can sometime not work in a build ? #GeneralQuestions

Hi guys, I’m doing a project and using for the first time a static class just for some generic function or function that I use a lot of time (Like a FollowTarget). But I add some reviews about using static class that it can be dangerous when I’ll build without more precisions. So I start a topic to obtain few data about it and for those who have the same question as me. As I’ve a deadline in 10 days, I’ll export the function in a few days, if I’m not sure about it but feel free to anwser even after that delay, it’ll be sweet :smiley:

static methods, fields, properties (and indeed entire classes) are all fine to use in Unity.

Be sure you understand precisely what static means or you may have very weird bugs.

They work but should not be used thoughtlessly.

  1. Domain Reloading. Unity is faster if you can turn Domain Reload off but this requires special handling for statics. This is especially important as a project grows in size. For a school project, it’s not a big deal.

  2. Hacky commnunication between scripts. It might be tempting to declare something static to let one script access some property of another, but this is bad habit. If you think you’re in this situation, post it for feedback.