Best way to do something after setting fields for a class?

I often find myself having to do run code (usually instantiating an object) in a class after setting the values for it. What would the best way to do it? Here’s a list of ways I thought of doing it so far:

Constructor - calling needed methods at the end of the class constructor

Setter Method- calling needed methods after setting the class values

Property setter - running the needed methods from the setter of that field

From the instantiator - after setting the fields, I run the needed methods from the object that instantiates and sets the fields

Why I am asking this as I do not want to fill up the script execution order list (i would know for sure that the fields were instantiated) or loop until the field gets assigned.

The listed ways above all seem kind of clunky to me. I want to know your opinion on this. Thanks :slight_smile:

Edit: I forgot to add that the instantiated class is not inheriting MonoBehaviour.

Edit2: Added picture, hopefully it helps you understand better the steps

As written here, you shouldn’t use constructors in MonoBehaviour derived classes.

So I’d instantiate a class, set the class public values direct or via so called “properties” (get set etc.).
Than I’d call a function to initialize the class (if you need with parameters) that is not awake() or start(), because this functions were already called upon component instantiation and thus would be called twice.

If you are not inheriting from a MonoBehaviour class, I’d always create a constructor and pass information upon instantiating it.

See Verwenden von Konstruktoren – C#-Programmierhandbuch | Microsoft Learn