Anakin Skywalker, the central character of the Star Wars prequel trilogy, received his facial scar during the events of the Clone Wars, a conflict that took place between the films Attack of the Clones and Revenge of the Sith.

In the Clone Wars animated television series, which takes place between the second and third films, Anakin and his Padawan learner, Ahsoka Tano, were sent on a mission to capture a notorious Separatist leader named Asajj Ventress. Ventress was a skilled warrior and assassin who had previously trained under the Sith Lord Count Dooku.
During their confrontation, Ventress and Anakin engaged in a lightsaber duel on a narrow ledge. In the heat of the battle, Ventress managed to slice Anakin across the face with her lightsaber, leaving a distinctive scar from his forehead down to his cheek. Despite his injury, Anakin was able to defeat Ventress and complete his mission.
The scar serves as a physical reminder of Anakin’s experiences during the Clone Wars, and it reflects the emotional turmoil he was experiencing during this time. Anakin’s anger and aggression were growing as he became more and more involved in the conflict, and this would ultimately lead to his fall to the dark side and transformation into Darth Vader in Revenge of the Sith.
It is worth noting that Anakin’s scar was not present in the earlier film Attack of the Clones. In fact, Hayden Christensen, the actor who portrayed Anakin, initially did not have the scar when he returned to film Revenge of the Sith. Instead, the scar was added in post-production using special effects.
In conclusion, Anakin Skywalker received his facial scar during a battle with Asajj Ventress in the Clone Wars animated television series. The scar serves as a physical reminder of the emotional turmoil Anakin was experiencing during the conflict and foreshadows his eventual fall to the dark side.