I can't pass arguments into constructor with AddComponent.

Here’s the situation. I want to systematically create GameObjects with scripts attached to them. The problem is, the script I want to attach is using a constructor with around 15 arguments, and AddComponent doesn’t let me pass them in. I could pass in the 15 arguments with 15 lines, but I feel like there should be an easier way. Could I create it separately and then attach it? I don’t know.

It seems to me that what you’re doing should be taking advantage of prefabs. Creating a multitude of gameobjects - each with a number of scripts on it - programmatically seems rather unnecessary. Perhaps you could instantiate some base prefab and just change a few of its values as is required.

If there is only one difference or two, you would only need to change what is different:

GameObject prefab = Instantiate(myBasePrefab);
if(shouldLoop)
    prefab.GetComponent<AudioSource>().loop = true;

Unfortunately, MonoBehaviours don’t take constructors, so the alternative would be to do something like this:

AudioSource source = gameObject.AddComponent<AudioSource>();
source.loop = true;
source.volume = 1f;
source.pitch = 1f;
//...

You might even be able to get away with just instantiating a bunch of prefabs (no add or get component required). It’s hard to tell without knowing more about your use case.

You can also try creating some setup function as an extension method, that would internally handle the creation logic:

AudioSource source = gameObject.AddComponent<AudioSource>();
source.Setup(shouldLoop);

You would just put the following in a static class:

public static void Setup(this AudioSource source, bool shouldLoop)
{
    source.loop = shouldLoop;
    source.volume = 1f;
    source.pitch = 1f;
    //...
}

I hope this helps!