Moving a list of objects to their starting position

So I’m trying to move a chain made of links to the location they start at but I cant get it to work. I have a list of game objects at the start I make a list of transforms from the game objects in the second list. I then call a method that equals the transform of each object on the list to its transform at the start. I did some debugging and the transform positions are the same in the debug window but for some reason the objects are not moving / resetting to their original position. Thanks in advance for anyone that can help.

[SerializeField] List<GameObject> rightChainList;
[SerializeField] List<Transform> rightChainStartPosList;

private void Start()
    {
        foreach (GameObject chain in rightChainList)
        {
            rightChainStartPosList.Add(chain.transform);
        }
    }

private void MoveChainsToStartPosition()
    {
        int startPosIndex = 0;
        foreach (GameObject chain in rightChainList)
        {
            chain.transform.localPosition = rightChainStartPosList[startPosIndex].transform.localPosition;
            chain.transform.localRotation = rightChainStartPosList[startPosIndex].transform.localRotation;
            chain.gameObject.SetActive(false);
            startPosIndex++;
        
        }
    }

Transforms are a reference type, in this example, you are caching a reference to the transform.
Line 17, chain.transform is same transform as rightChainStartPosList[startPosIndex].transform

you need something like

[SerializeField] List rightChainStartPosList;
[SerializeField] List rightChainStartRotList;

  • foreach (GameObject chain in rightChainList)

  • {

  • rightChainStartPosList.Add(chain.transform.localposition);

  • rightChainStartRotList.Add(chain.transform.localrotation);

  • }

That did it.
So just for clarify: If I reference a transform of an object it will always be its current location and rotation and scale . You can only pull information out of it and save it in other locations?

Sorry If I’m not using the correct words pretty new to programming.

Yeah, exactly, so the following would be true
Gameobject MyObject;
Transform First = MyObject.transform;
First.position = Vector3.zero;
Transform Second = MyObject.transform;
Second.position = Vector3.one;

First.position would now equal Vector3.one, because First and Second are referencing the same Transform object (object as in the OOP term, hopefully not making things too confusing).