As the star collapses, fusion occurs in the core of the star. This process compacts atoms and if the star is sufficiently massive, stellar nucleosynthesis takes place and heavier elements are formed. If nuclear fusion is unable to prevent gravitational collapse, the star will blow itself apart as a supernova, ejecting the heavier elements into space at very high speed. So space is seeded with heavier elements, to be captured by the gravitational attraction of other celestial bodies and absorbed into solar systems.