Unity Issue: No solution after hours of looking, GameObject.transform.position does not set to a fix

So I wanted to make a simple teleporter, where when the player reacts with a trigger they should change their position to a fixed Vector3 value. I have scoured for hours and no solution has worked.

(The problem is in the line tpObj.transform.position = linkedTP.tpPoint;
)

My code:

using UnityEngine;

public class Teleporter : MonoBehaviour

{

public Vector3 tpPoint;

public Teleporter linkedTP;

public GameObject tpObj;

private void Start()

{

tpPoint = transform.position;

}

private void OnTriggerEnter(Collider other)

{

if (other.GetComponent().tag == “Player”)

{

tpObj = other.gameObject;

tpObj.transform.position = linkedTP.tpPoint;

}

}

}

The code runs to the end, and I even tried a separate script for setting the player’s position to Vector3.zero, but that failed. There are no messages in the console. Also while I know this should teleport the player in an endless loop, it doesn’t as I checked with a Debug.log. I know this is a beginner issue but any help would be greatly appreciated.

The code itself looks like it should work (though it has some extra unnecessary bits). Obviously as you said I would expect that the player might end up teleporting back and forth very quickly if there’s another teleporter at the other end, but just for testing you should just disable the second teleporter to test with. What debugging have you done? Have you tried Debug.Log to make sure your OnTriggerEnter code is even running and that you are seeing the tag you expect on the player?

One possible reason this might not work is if your player has a CharacterController or Animator on it. Either of those components is known to overwrite changes to transform.position. If that’s the case what usually works is to disable the CharacterController, move the player, and then re-enable the CharacterController.

I did have a CharacterController and that was the solution, thank you lots.