Search Unity

Feedback Attribute or trigger for start or domain reload

Discussion in 'Scripting' started by Thaina, Jan 21, 2022.

  1. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,166
    When the domain reloaded. Sometimes the script that ExecuteInEditmode or ExecuteAlways rely on the variable that was cleared and has to reinit its own state too. And so I think we should have attribute to mark a class or instance function or interface to declare that, after domain reload, this script want to be Start again, or have some Init function to trigger it when domain reload but after script start

    Like InitializeOnLoadMethod but on instance level component in the scene
     
  2. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    547
    The closest think I can find to what you describe is the OnEnable method
     
  3. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,166
    Yes, but OnEnable also trigger when it just disabled and enabled. I want to have specific OnStart that only trigger just when it start or domain reload

    In fact, Start function should trigger on domain reload. But it would be breaking change so it should have attribute or specific function for this
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,929
  5. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,166
    I already did that but I propose that this should be officially standardized in unity and anyone who want to do this should use the same pattern