That is a great question!!!
And I will give here a description of 3 cases.
Sumer
The Sumerians myths are closely formed by 2 epics/cycles/matters/stories. The Cycle of Aratta, and the Cycle of Gilgamesh (not to be confused with the Babylonian Epic of Gilgamesh).
The cycle (I will use cycle here) of Aratta is telling the story of the fight between the City of Ur and the city of Aratta and the defeat of Aratta. It is formed by 4 different stories. In the first one, the conflict is solved by psychological warfare and diplomacy. In the 3 others by traditional war. It involves the legendary king Enmersikar, and the hero Lugalbanda (father of Gilgamesh).
Now let's talk about history. Sumer (and to some extend Mesopotamia) was not a kingdom in modern sense but a bunch of city states with no real cohesion, very similar to the Greek City states. We know for sure they was in constant war status/rivalry between each others. One of the story with Gilgamesh shows us Ur in conflict with another city.
On that the Cycle of Aratta truly reflect the war status in Sumer. It shows us that Sumerians was aware of diplomacy and war as mean to subdue foe. Now, per se, both Sumerians cycles are recent, they date from late Ur dynasty shortly before the end of Sumer. They are obviously propaganda material made by late Urian rulers wanted to show the strength of Ur and their own legitimacy.
To what extend does it reflect an actual conflict? Considering this is late writing, we can't tell, and the diplomatic writing in 3000 B.C. are let's face it inexistent. Gilgamesh was dead from a long time and the fight between Ur and Aratta long finished. But as with later Troy we can safely assume, from our knowledge of the status of Sumer, that a war between Ur and Aratta could have happened. We know also Ur was lacking some resources (stones here) and subduing such a city was of interest. So we can assume for Sumer both their great cycles are based on "related historical events". And also they totally reflect something: the constant war status that will plague Sumer and finally led it to its demise when king Hammurabi of Babylon put an end to Sumer.
Suggested reading:
- The Matter of Aratta by Leo Oppenheim
- King Hammurabi by Marc Van de Mieroop, I give this one just because it is one of the first documented king we have and this recent edition includes the recent find of the Mari's archives. It gives you a good idea of the true warfare status during Hammurabi's time as well as how he solved conflict with wars and diplomacy.
Egypt
I suspect anyone know about Horus, Osiris, Ra and such...
The first thing to see is Egypt is 2500/3000 years of history. Comparing predynastic time, Old Kingdom, Middle Kingdom and New Kingdom is at best funny. Here is a predynastic document (the Narmer tablet):

Anyone will recognize Horus here as a falcon. The bulls we see are the Goddess Bat. And basically it is known that it depicts the unification of the two Kingdoms of Egypt (Upper and Lower) during Narmer's reign (before the first dynasty, so during dynasty 0).
Is is suspected that the mythological fight between Horus and Set is a representation of the fight between Upper and Lower Egypt (the two kingdoms). Notice the tablet here does no represent Set, when it links Narmer with Horus (see the falcon). So to what extend the fight between Horus and Set could represent that unification. Knowing that it is unclear who conquered what (Upper to Lower or Lower to Upper) this is an uneasy task.
Horus has vastly be a god related to the Pharaoh. It is so old that even in predynastic time He is there. One thing is sure. Most of the legend surrounding Horus (and Set) are post Old Kingdom (post pyramid text). At a time when Egypt is largely two Kingdoms. What could be the chance that Egyptian in Middle Kingdom, who was everything but historians, knew anything about the unification events?
Suggested reading:
Europe
Finally let's talk a little bit about Europe. During Middle Age there is the infamous Matters, Italian, French and English. The English one are about King Arthur which probably was an historical figure. Note that on a pure historical way, talking about 'French' and 'English' is quite a mistake. English Arthurian cycle really start with the Plantagenet, Both Henri II Plantagenet (founder) and his wife Alienor of Aquitaine was both French and the main writers Chretien of Troyes is French.
But we don't know a lot about the historical Arthur. Fortunately for us the French Matter is about King Charles. And here we know. Let's give a short summary. The Roman empire is conquered by Germanics Barbarians (Ostrogoth, Wisigoth, Franks, etc.). One of them the Franks (modern France come from them) will give two great dynasties first the Merovingians (cf. The Matrix movies) then the Carolingians. One of the main Carolingian figure is Charlemagne the subject of French Matter.
Charlemagne is well known for 3 features:
- He became Emperor, de facto becoming the Roman successor
- He vanquished the Saxons, that neither the Romans nor the Merovingians managed to handle
- He tried to conquered the Muslim Spain, this one is a subject of the French Matter
On a pure historical fact, the conquest of Spain was a political gesture (toward Rome and the Pope) as well as promise of richness. One of the greatest feature of Charlemagne was to understand this was an horrible mistake and quickly withdraw and concentrate on the Saxons, the goal of his life. This actually shaped Europe between England, France, Spain, and the Germanic Empire. Would he had tried to stay in Spain, history would be vastly different. His withdrawal from Spain is on the same level as the heroic Greek's resistance against the Persians.Greece outshined the world after the Medic Wars. Without the Greeks stopping the Persians, no Socrates, no Plato, no Euclid (No maths, no physics, no philosophy). Considering Charlemagne could not handle both the Saxons and Spain, no one can express how smart a gesture this was.
One of the greatest song of Charlemagne is about his retreat from Spain when his rear army, lead By Roland was attacked and defeated and Roland exploding his throat by blowing his horn. This was an historical event, about a "Frankish defeat" (put that on the same level as the Thermopilae is a Greek defeat). Now the heroic features presented in the Matter are totally unreal (even Roland's death...), but the event is. We have here the chance to track the difference between the Matter presenting a defeat as a final victory and the purely historical "defeat".
We can safely here do so safe comparison between Arthurian Matter which perhaps used an historical figure (A guy named Arthur). And the Charles Matter which used an historical figure that we know. In both case, anyway, the resulting figure appears very different. You do not have an idea of the politics or mind of the people of Arthurian or Charles time. Those are Chivalry novels. On the same way we can assume the Cycle of Gilgamesh/Aratta are far from the preoccupation of Gilgamesh.
Suggested reading
Sumary
Do myths/legends come from actual historical events? If the song of Roland actually did, if the Iliad and the Odyssey did, The Medic Wars were covered only by Herodotus. Knowing their historical importance vastly outlive the Trojan war. If the Cycle of Aratta or Gilgamesh could cover historical events, we don't know what those events were, and anyway it was written long after those events, and in such a style this makes it questionable.
We know finally something, when Herodotus talked about Egypt he is telling us something important about what the Egyptians knew of their history in 450 BC: They were parroting their not well read books! The Khufhu (Cheops) they are talking about is the one we could read the story in their books.
In case of the Matters written when writings were more common, the actual use of historical material (and such this sliding from history to myth) is obvious.