As far as Hasbro was concerned, the key takeaway from Star Wars was toy sales hinged on kids seeing characters they were keen on appearing in riproaring adventures. The Rhode Island toy company duly approached Marvel, the "House of Ideas," to come up with characters and storylines for G.I. Joe and then Transformers.
(This was not unprecedented. Marvel had previously published comic tie-ins for Parker Brothers' Rom, Mego's Micronauts and Mattel's Shogun Warriors.)
This was, as they say in business, a win-win proposition. Hasbro would get another marketing tool for its toylines while Marvel would profit from comic books being advertised on television by Hasbro. Marvel had learned an important lesson from Star Wars as well. The comic book company was saved in the Seventies thanks to the record sales of the Star Wars comic tie-in.
The Marvel Transformers comic book was quickly followed by the Marvel Productions cartoon, the Marvel UK comic, Japanese manga and anime, and the line is still promoted today through a variety of media.
The one constant throughout all this is you can rest assured, sooner or later, Optimus Prime will die. He may be the greatest Transformer of them all but he does have an uncanny knack of croaking and he's demonstrated this on a regular basis in comic books, on television and in movies. Sometimes, it was decreed by the toy company. In Hasbro's thinking, there was little point in featuring a character who no longer had a toy selling in stores. On other occasions, Prime's death was simply due to a writer wanting to give less prominent characters a chance to shine.
Perhaps the most surprising death of all occurred in issue 24 of the Marvel US comic book. "Afterdeath" saw Optimus Prime take on Megatron in a duel within a videogame with the loser being executed in the real world. Prime won the encounter but shocked everyone when he confessed he had cheated. In defeating Megatron, Prime had knowingly let an NPC die -- something he would never have done in the real world. His moral rectitude led him to conclude he had broken an unwritten rule of the game; his conscience demanded he speak up and suffer the consequences.
(In gaming terms, this could be deemed an exploit. If a multiplayer game is being ruthlessly exploited by some in order to gain a competitive advantage over the rest, gamers disillusioned by this unfairness might be tempted to try another game even if its designers had a long wretched history of exploitation themselves. Thus, it's absolutely imperative game designers act promptly to enforce existing rules, plug loopholes and deal decisively with cheaters. With all that said, capital punishment still seems a disproportionate penalty for videogame cheating. Imagine kids being summarily executed for using Game Genie on the NES.)
There was a slight complication with all these deaths, corporate-mandated or otherwise. If the whole point in having a media tie-in was to promote the toys to young impressionable minds, getting rid of those now-familiar characters would not go over well -- particularly when it was done in a brutal fashion. The most notorious example of this was the 1986 animated movie, which was not inaccurately dubbed "Instant Childhood Trauma: The Movie" by one Usenet wag.
But perhaps G.I Joe comic book writer Larry Hama put it best: "It’s too easy to forget that the purpose of showing these dark events is to demonstrate that it is possible to triumph over them. Yes, bad things happen to good people, but we get over them and we move on, and we are stronger."