Why do I not get a boner during sex but I normally get one?

So I don’t really know what to call my condition because I can get a boner without stimulation through your the day normally and even when I’m masturbating or looking at something stimulating online I get hard but two instances within a week I was not able to become erect during sex but the last time I had sex before than which is 4 years ago and I was able to become fully expect during sex. I’ve only had sex 4 times with these two times me not getting hard and I was able to get hard minutes after both time with online stimulation but when I was in the act I couldn’t. What should I do.

Ps: I also smoke weed and I don’t know if this might effect it two or the fact that the two most recent times I was having sex with the escorts. Im also 19 years old so this is weird and I don’t want to resort to no pills.