Creating melodies or a melodic line is not much different than creating a figure in drawing.
I see two ends of a spectrum of choices with everything in between as possible.
I. Derivative melodies are a subjugation of environmental influences literally and figuratively. Examples include the following:
A melody based on songbirds.
A melody based on car horns in rush hour traffic.
A melody or texture based on the ocean surf.
A melody based on a woman talking (often used by Blues guitar leads).
A melody based on machinery, "Ballet Mécanique" by George Antheil.
A melody based on fire, wind, or rain, "The Four Seasons" (Italian: Le quattro stagioni)...a set of four violin concertos by Antonio Vivaldi, or "Sonic Seasonings" by Wendy Carlos formerly Walter Carlos.
II. Original melodic content is based purely on imagined sounds.
Examples include the following.
Improvised on the spot and in the moment such as melodies by Classic North Indian Raga Singers, and many Jazz and New Music composers/performers.
A melody where sound is totally aleatoric. (John Cage 4' 33")
A melody that accomplishes a specific compositional goal, e.g. 12 tone atonal music.
A melody where technical skills permit pitch organization in a super human way requiring mechanical and/or electronic and/or computer engineering such as the electronic music of Edgard Varèse, Karlheinz Stockhausen, Maggie Payne, The HUB, David Behrman and many others.
III. Somewhere between these two extremes:
A melody that furnishes a good thread to connect harmonic content or based on a chord progression, most of Jazz.
A melody that defines a musical form such as counterpoint.
While the above is brutally simplified, it allows a wide set of guidelines to permit almost anything to be constructed into melodic content.
Music theory from any culture, study of scales, study of musical literature all have a place in assisting the composer in sculpting a melody, but are as confining as using a ruler or French Curve for the artist. These things are best used as guidelines and measurements for proportion and compositional form but can not be greater than the emotional content endowed by the composer and brought to life by the performer.
Regarding "melodies is something that cannot be learnt".
If one can learn to walk then one can choose to journey.
If one can learn to talk then one can be heard.
If one can listen then one can learn from others.
If one can read and write then one can compose letters and understand those sent.
If one can make art (music, dance, figures) then one can connect from one heart to all.
Composing is simply making choices whether you are looking at melodic content or a symphony. The more you learn what options you have to choose from the better you will become with making your idea real.