Changing the parent of an object gets rid of its parents?

So i have 3 objects, A,B, and C. A is the parent of B, and i want to set C’s parent to be B. But when i use SetParent, C.transform.parent = B.transform, or instatiate C with B as the parent, in every case B stops being a child of A. I know i can just run more code every time to set A as the parent of B, but it feels like there should be a better way of doing it then that.

A and B are a part of the same Prefab and C is a seperate one. i dont know if this changes anything, but it might be relevant. Any Ideas?

EDIT; It turns out i am an idiot and forgot about this horrible bit of code i hid in C.
transform.parent.parent = A;
I removed this and all my problems were solved. Instantiating works, changing C’s parent to B works, all of it. i just was dumb.

This may be due to the use of prefabs.

Make sure A. is instantiated (or already in the hierarchy).

Also make sure that the A that is the parent of B is the one in the hierarchy (not a prefab)