Assign references in inspector via script

Hello everybody.

I have a script, which has:
[SerializeField]
List AllObjects;

I can fill this list using Inspector. Drop each GO to the field’s area.

But I’d like to have another script, which may automatically assign objects (with some condition, like “Has component”) to the list. Every object, which meet the condition must be added to the list.

I have no idea, how to write such a script. Can someone help me?

Also. I can solve this by use Resources.LoadAll(pathToFolderWithObjects);
But as I understand, it’s not a good solution.

If you want to add assets/prefabs out of the Project-Asset folder (?), I know 2 solutions.

First, you can load per Resources.LoadAll. It’s ok if you do it just one time at the start of the project. You will probably need a static access method to the list to share the list with other GOs in the scene.

Or you can use a ScriptableObject. You still have to add all assets/prefabs by yourself, but you can do it right in the asset folder and put just the one scriptableObject (as SerializedField), that holds the list, everywhere you need the objects.

ScriptableObjects are like global DataStorage right in the Projekt - you need no Instance in the scene - and it provide you the references to all Assets / Prefabs.