Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Trouble updating cloned prefabs transforms.position

Discussion in 'Prefabs' started by MachineHead, Jul 21, 2021.

  1. MachineHead

    MachineHead

    Joined:
    Jan 6, 2016
    Posts:
    21
    I have a Parent object that instantiates a prefab that's a path that's essentially a Bezier Curvehttps://en.wikipedia.org/wiki/Bézier_curve made of multiple transform points stored as children. When the path is instantiated, an object, a projectile, is supposed to follow the path.

    The object only follows the prefabs transform that I initially saved it at, transform.xy and z are at 0. It's not following the new Vector that is established when the path is instantiated during runtime via a reticule that moves around the screen. Upon further inspection, the parent object transfrom of the path is updated with the new vector when instantiated, but the child objects that make up the Bezier Curve, are still at 0. So it follows that initial path that was saved, and not the updated Vector of where the new path prefab was instantiated.

    Why is it following the initial game objects position that was saved when it was created as a Prefab, and not the new Vector the Prefab is instantiated at?
     
  2. MachineHead

    MachineHead

    Joined:
    Jan 6, 2016
    Posts:
    21
    Haven't solved my issue yet, but the trail I'm on is to use "Transform.SetParent" to get all the child transforms in the array that the Bezier Curve uses and update those positions along with the Parent Transform when it is moved by the player.
     
  3. MachineHead

    MachineHead

    Joined:
    Jan 6, 2016
    Posts:
    21
    Welp, changed the path system I was using and opted to using a Sine Wave. Got it to work, and got the prefab to reference a new vector of where it was instantiated. I needed the X coordinate of the object doing the instantiating so the Sine Wave of the prefab being instantiated would have that as its straight line to oscillate around.

    You have to store a reference to the updated vector via a variable or use a "Get" method to get the updated vector.

    Currently having an issue with that now with a player prefab, seeing the vector is being updated as a new vector.

    I'll figure it out. Thanks for the silent treatment.
     
  4. MachineHead

    MachineHead

    Joined:
    Jan 6, 2016
    Posts:
    21
unityunity