ive tried starting coroutine in the constructor but that did not work
If you want help, I’ll need to see some of your code. That being said, try the Start() method instead.
I dont think using the Start method would work in this scenario, here is my script:
https://pastebin.com/75EegSwQ
You can’t provide a ctor() for a MonoBehavior-derived class.
Not only that but the actual ctor() created (implied) does not run in the main thread: it actually runs in a secondary loader thread that Unity uses for fabricating and connecting that kinda stuff deep inside the engine.
That’s also why you cannot use the new keyword with MonoBehaviors. It’s only valid to use .AddComponent() on a GameObject to make them.
MonoBehaviours don’t support constructors, as you aren’t going to create them using “new”. As mentioned, if you use AddComponent, you’ll want to probably do the wait in Start(which can be a coroutine)
Technically, you can have a parameterless constructor for a MonoBehaviour, and it will get called. But it won’t necessarily get called at the time you expect, it might get called more than once per object, and there is very little (if any) Unity-specific stuff that it could safely do. It could initialize some plain C# variables. It can’t start a coroutine.
That’s why MonoBehaviours have magic methods like Awake(), Start(), and OnEnable().