Search Unity

Question OnEnable not triggering in script on prefab.

Discussion in 'Scripting' started by RDT42, Aug 18, 2021.

  1. RDT42

    RDT42

    Joined:
    Jun 12, 2018
    Posts:
    5
    I have a script on a prefab, and I want to create some editor specific behavior. However, OnEnable doesn't trigger at all. I am using the [ExecuteAlways] attribute on the script. The Prefab is not present in the scene, is that a problem? It's also not in the Resource folder, but moving it there didn't seem to make it work regardless.

    Is it possible for this to work, and if so, how?
     
  2. vectorized-runner

    vectorized-runner

    Joined:
    Jan 22, 2018
    Posts:
    398
    You can use InitializeOnLoad attribute on a static class, I think that's what you're looking for. You should use ExecuteAlways when you have the instance on the scene.