how to transform back into child of object

I’m new to scripts so nothing i try to change works. So the problem goes like this :when my character jumps on the moving platform he moves with it just fine, but when he jumps off from the moving platform he is not the child of anything and that’s the problem since the character needs to be the child of an empty object to move properly. The moving platform uses this script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HoldCharacter : MonoBehaviour {

void OnTriggerEnter(Collider col){
    col.transform.parent = gameObject.transform;

void OnTriggerExit(Collider col){
    col.transform.parent = null;


the character must be the child of “crashmain” object

The argument Collider col is the collider of your player (or whatever enters your platform).

In OnTriggerEnter you set your player’s parent as the platform.

In OnTriggerExit you set your player’s parent to null.

A couple ideas:

  1. Add a reference to the player parent object (crashmain) as a public variable to HoldCharacter. Something like: public Transform crashmain; (you will then have to drop the crashmain object into HoldCharacter in the editor) and then assign it as your player’s parent in OnTriggerExit like this: col.transform.parent = crashmain;
    Or 2) Do not replace your player’s parent object at all. Instead set crashmain’s parent as your platform. Like this:

    col.transform.parent.parent = gameObject.transform;

    col.transform.parent.parent = null;