I guess it would be down to your profile and if your known with narcotics previously. And on top of that any previous court hearing between you two.
I mean it's not always the worst thing, so long as your supporting your child, paying your own way in life, not claiming every benefit under the sun. Then what's the difference on the choice of drug, people drink, alcoholics still see their children, it's just because it's labelled illegal, anything that enhances our natural state as human beings is a drug. Anyway I'm not an expert, but I think you'll be ok, if you hold your hands up and admit you was stupid at the time, maybe worst case enroll on a rehabilitation course, to prove you want to do something about it, even just to keep the peace.
I'm no expert in drugs and or testing.
But I imagine if its the first time you've used in a long time or if at all. By the time the court hearing would come around, then the time for a drugs test I expect it might be out of your system.
Again this would depend on if you used regularly if at all before these 3 months, and what kind of drugs test they do eg. Urine, Blood, Hair etc
Have a look on the Internet to see how long the recreational drug you used stays in your system when used once.
As I've said I don't know everything or all the ins and outs of this subject, only my opinions, do some research on it I hope this has helped even if just the slightist.
I'd google it to check the sensitivity - they normally do a hair strand test, but this will only come up if your ex mentions that you've taken drugs. If you've only used it once, the tests will hopefully show a minimal usage, but definitely worth checking.