How can i make my object go back to its start position?

I’m a new beginner at c#, I’m wondering how I can make an object basically “teleport” or go back to a different location after it hits a trigger? basically, I have a rock that is moving towards a target, but before it gets there, it goes through my “trigger” but I want my rock to go back to it’s starting position after it hits it.

Put this at the top of your object’s script:

Vector3 startPos;

Then somewhere inside your object’s Start or Awake function:

startPos = this.transform.position;

Then whenever you want your object to go back, you can just do this:

this.transform.position = startPos;

I had the same issue. @Scrubbzi
Thank you @Chubzdoomer
I was able to fix mine with this code - note that, I am using a VR controller hence the ‘OnDetachedFromHand’ otherwise, everything else should work well.
First, you get the position of the object,
You get the rotation of the object,
Upon detach from hand, you send the object back to those positions.
I hope this is helpful.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR.InteractionSystem;

public class SnapToPosition : MonoBehaviour
{
    private Vector3 snapPosition;
    private Quaternion originalRotationValue;
    float rotationResetSpeed = 1.0f;

    private void Start()
    {
        snapPosition = this.transform.position;
        originalRotationValue = transform.rotation;
    }

    private void OnDetachedFromHand(Hand hand)
    {
        this.transform.position = snapPosition;
        transform.rotation = Quaternion.Slerp(transform.rotation, originalRotationValue, Time.time * rotationResetSpeed); 
        GetComponent<Rigidbody>().isKinematic = true;
    }
}

I had the same issue. @Scrubbzi
Thank you @Chubzdoomer
I was able to fix mine with this code - note that, I am using a VR controller hence the ‘OnDetachedFromHand’ otherwise, everything else should work well.
First, you get the position of the object,
You get the rotation of the object,
Upon detach from hand, you send the object back to those positions.
I hope this is helpful.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR.InteractionSystem;

public class SnapToPosition : MonoBehaviour
{
    private Vector3 snapPosition;
    private Quaternion originalRotationValue;
    float rotationResetSpeed = 1.0f;

    private void Start()
    {
        snapPosition = this.transform.position;
        originalRotationValue = transform.rotation;
    }

    private void OnDetachedFromHand(Hand hand)
    {
        this.transform.position = snapPosition;
        transform.rotation = Quaternion.Slerp(transform.rotation, originalRotationValue, Time.time * rotationResetSpeed); 
        GetComponent<Rigidbody>().isKinematic = true;
    }
}