What happens next?

How to get rid of fungus gnats
Keep soil fairly dry.
Fungus gnat larvae thrive in wet soil. If you have plants that you water in pots or in your yard, don't do so excessively.

Select from: a. Your gnat population would jump from one plant to another based on dry weather. Use a dehumidifier if you have very dry summers. b. Build a well over the area where your caterpillar has set up its tiny nest, and add a bit of mulch under that before it starts laying its eggs. Extend the caterpillar's flight path with plants. c. You'll need to water for several weeks after the larvae become viable. Keep the soil about 6 inches (15 cm) deep and prevent the plant from drying out. d. Many plants only need to be watered infrequently. If you aren't sure how often to water your plants, do an internet search or consult a gardening guide for recommendations for each type of plant.
d.