Skip to content

A couple of attributes that help disabling Domain Reloading in Unity easier

License

Notifications You must be signed in to change notification settings

GodwinTsai/unity-domain-reload-helper

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unity-domain-reload-helper

A couple of attributes that help disabling Domain Reloading in Unity easier. By default, there are a few attributes to aid in resetting static fields. These are however quite clunky. Here's a few helpful replacements!

ClearOnReloadAttribute

Use on static fields, properties or events that you wish to reset on playmode. You can either "clear" the field (set the value to default), set it to a specified value, or make it assign itself a new instance of its type.

ExecuteOnReloadAttribute

Use on static methods that you want to execute during a domain reload.

Examples

public class CharacterManager : MonoBehaviour
{
  //Will set value to default (null)
  [ClearOnReload]
  static CharacterManager instance;
  
  //Works on events!
  [ClearOnReload]
  static event Action onDoSomething;
  
  //Will set value to defined value (10)
  [ClearOnReload(valueToAssign=10)]
  static int startsAsTen;
  
  //Will reset value, but make it not null (creates a new instance)
  [ClearOnReload(assignNewTypeInstance=true)]
  static CharacterManager myNeverNullManager;
  
  [ExecuteOnReloadAttribute]
  static void RunThis() 
  {
      Debug.Log("Clean up here or something")
  }
}

About

A couple of attributes that help disabling Domain Reloading in Unity easier

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%