C# Parent find child's Vector

Hello I’m on a games course and I’m struggling with something…

Basically I’m trying to create an endless runner, I’ve got it set up so that the platforms all generate from an object-pool with an empty child-object on there ends that will (in theory) act as a “socket” for the next track.

I want the platform/parent to be able to have an internal int equal the value of the of the child’s vector X.
Grabbing hold of the object’s value directly is not an option.

I’ve managed to come quite far with object pooling and such but I can’t find anything on this, so I’d really appreciate any help offered.

public Vector3 vectorPosition;

void Update ()

  • {*

  • CountDown();*

  • AutoMove();*

  • WheresMyBaby();*
    //^^I call the function here (just to check that it works (which it doesn’t))

  • }*

*//<<<Some functions regarding movement and object activation go here… *
public void WheresMyBaby()

  • {*
  • vectorPosition = GetComponentInChildren().WhatsMyVector();*
  • //^^I’ve got this non working device currently, the idea being that I my script…*
    //attached to the vector will “reply” with its coordinates
  • }*

Why not?

I beg your pardon, I shouldn’t really rule anything out, but when I say “grabbing hold of the object’s value directly is not an option” I meant to say that I wanted it to go through the parent since there will be many clones of the parent with a child.

Programming is not my forte though, I was more looking for a simple line of code that will go something like…
vectorPosition = Child.position.x

I’ve no clue though and would appreciate any help.

You’ve got a lot of options and it depends on how complex your setup is and how consistent it is. If the child always has the same name then in the parent you can do transform.Find(“childName”) to get the child. You could have the child tell the parent by writing a method in the parent to store the value and in the child writing transform.parent.SomeRegisterMethod(transform.position.x)

I will look into it, thank you for the help.