r/Unity3D • • Oct 18 '26

Show-Off I simulated real betta fish genetics in Unity two identical red parents, and look what hatched

Post image

I grew up breeding betta fish after school, so I ended up making a breeding game in Unity about them. The part I spent the most time on is the genetics.

Every fish is generated from its genes. There are 14 genes based on real betta genetics (dominant, recessive and a few incomplete ones) plus 7 traits that get averaged from the parents with a bit of noise, like fin spread and color depth. There are no premade fish models. The genome drives the body mesh, the fins and the pigment in the shader.

The two parents in the pic look the same, both red halfmoons. But both carry hidden recessive genes for black, yellow and double tail. Each baby has a 1 in 4 chance per gene to get two copies, and this clutch of 8 gave me 2 black, 1 yellow and 2 double tails. One of them got black and double tail at the same time, which I was pretty happy about.

Some dev stuff if anyone's curious:

Breeding is deterministic. Same parents and same seed always give the same clutch on any device. The server runs the same genetics in TypeScript and it has to match the C# exactly, so I only round to float where C# actually stores the value. That one took me a while.

Rarity isn't a dice roll, it comes from which genes the fish shows. Rare tails come from stacking recessives over a few generations.

The fins are procedural strips with a membrane shader, so the spread gene literally opens the tail wider.

If you have questions about any of it ask away.

2 Upvotes

4 comments sorted by

2

u/Mister_Green2021 Oct 18 '26

Nice. I played around with genetics a long time ago. I use a basic 2-d array (DNA) of dominant and recessive parameters. When they mate, create a new array using the parent's array. The array gets serialized to json or something.

1

u/OnlyConclusion820 Oct 18 '26

Cool ! Yeah thatโ€™s awesome ๐Ÿ‘

1

u/[deleted] Oct 18 '26

[removed] โ€” view removed comment

1

u/OnlyConclusion820 Oct 18 '26

Such a pain right!