Version: 2021.3
言語: 日本語

InitializeOnLoadAttribute

class in UnityEditor

マニュアルに切り替える

説明

Allows you to initialize an Editor class when Unity loads, and when your scripts are recompiled.

Static constructors with this attribute are called when scripts in the project are recompiled (also known as a Domain Reload). This happens when Unity first loads your project, but also when Unity detects modifications to scripts (depending on your Auto Refresh preferences), and when you enter Play Mode (depending on your Play Mode configuration).

Asset operations such as asset loading should be avoided in InitializeOnLoad methods. InitializeOnLoad methods are called before asset importing is completed and therefore the asset loading can fail resulting in a null object. To do initialization after a domain reload which requires asset operations use the AssetPostprocessor.OnPostProcessAllAssets callback. This callback supports all asset operations and has a parameter signaling if there was a domain reload.

See Also: running editor code on launch.