Skip to main content
1 of 4
Ed Marty
  • 5.3k
  • 1
  • 14
  • 15

A naive (simple) approach would be to simply have an object which encapsulates the state you want and store it in a static field, then access that field in Awake.

    public class MyComponent : MonoBehaviour {
      [SerializeField]
      private bool someParameter;
      [SerializeField]
      private int anotherParameter;

      public class InitInfo {
        public readonly bool someParameter;
        public readonly int anotherParameter;
        public InitInfo(bool someParameter, int anotherParameter) {
          this.someParameter = someParameter;
          this.anotherPatameter = anotherParameter;
        }
        void Apply(MyComponent c) {
          c.someParameter = someParameter;
          c.anotherParameter = anotherParameter;
        }
      }
      public static InitInfo OnAwake;
      
      void Awake() {
        if (OnAwake != null) {
          OnAwake.Apply(this);
          OnAwake = null;
        }
      }
    }

and elsewhere:

  MyComponent.OnAwake = new MyComponent.InitInfo(true, 5);
  Instantiate(myPrefab);
Ed Marty
  • 5.3k
  • 1
  • 14
  • 15