“The fans are going to come as who they really are: as Klingon warriors or as Andorian princesses or as Starfleet officers,” said Mr. Takei, who is an awfully good sport even when local television hosts come back from a commercial break dressed in Trekkie drag — which, yes, has happened to him lately.

He was in a more serious mode as he talked about the internment camps, yet his recollections of them were often surprisingly warm: the memories of a little boy whose parents shielded him from their own anguish. They allowed him to find joy and adventure in what he calls his “childhood imprisonment,” when his family was shipped off first to Rohwer, Ark., and later to a high-security camp in Tule Lake, Calif., where the watchtowers became a normal part of his landscape.

Those years of his life were a strange mix of sweetness and horror. Ask him about his first day of school, and he will recall being dropped off by his father, who hovered nearby and consoled him when he got scared. But the kindergartners were all fresh internees, their classroom a spot on the cement underneath the grandstand at the Santa Anita racetrack in California. The track served as a holding place for a few months while construction on the camps was being completed.

Image Mr. Takei with Walter Koenig in “Star Trek.” Credit... Paramount Pictures/Getty Images

“We were housed in the horse stables,” Mr. Takei said. “Can you imagine, for my parents to be taken from a two-bedroom home in Los Angeles, with their three children, and to sleep in this smelly horse stall? But to me as a 5-year-old kid: ‘I get to sleep where the horsies sleep! I can even smell them!’ For my parents, it was degrading, dehumanizing; it was a horrible experience. But my memory is that it was fun.”

A sense of fun is also part of “Allegiance,” because for its characters life does go on inside the camp. Like the teenagers Mr. Takei remembers from internment, the young people in the musical enjoy dances and romances. Like his mother, who smuggled her portable sewing machine into the camps and made curtains for the family’s barracks, the internees try to add beauty to the place where they find themselves.

For Mr. Takei, “Allegiance” is a rare foray onto the New York stage, where he first appeared as a replacement in the Off Broadway civil-rights musical “Fly Blackbird!” in 1962. He has more recent theater credits from both America and England, but he is more often found in the audience. Ordinarily, he said, he’s at a show almost nightly when he’s in town.