Changing parent on collision

Let’s say I have 2 cubes, cubeA, cubeB and cubeC.
I want to have it so when cubeA or cubeC hits cubeB, the cube’s parent is changed to cubeB’s parent. I have attempted to do this myself, however the variables that I get relating to the colliding cube is read-only, so I can’t get it to change parents.

cubeA.transform.parent = cubeB.transform.parent;

Thats all you need to do. If you are having trouble with that then there is something else wrong with your code and you need to show it to us.