How to call a static function at game start

Hello Unity Answers and thankyou,

I’m new to Unity and loving it so far. I’m setting up basic game tools and functions I’ve used in previous code, and for things like Dictionary initialization I would want to call a static function for it when the game initializes, not when each scene starts. Is this possible in Unity? I know Unity is structured very differently to the traditional Main() loop and so on, and I should work with scenes and empty game objects, but for this kind of limited thing, it’d be better to make the call only once.

Thanks

Matt the Pie

A common design practice in Unity, is to have a first empty scene.

This scene will usually handle at least two things:

  1. Have some empty game object(s) with global initialization scripts (like the one you seem to need, this is where your static initialization should go).
  2. Have some game objects that are set to not destroy on load.

This initial scene of course, loads the next “Welcome” or Menu scene of your game.