Due to formatting of other game elements, I'm having to move objects around, slightly to accommodate a shifting user requirement (as in one player vs two player) As such, the game play remains the same, but I want to move a couple of key elements. Thus: prefabInstance = (GameObject)Instantiate(prefab); prefabInstance.SetActive(false); prefabInstance.transform.SetParent(template.transform.parent, false); prefabInstance.transform.position = template.transform.position; prefabInstance.SetActive(true); GameObject go = GameObject.Find("ChildObjectFoundInPrefab"); go.transform.position = Vector3.zero; //go.position = tf.position - tf.position; When I go to the inspector, the position is something like -303, definitely not zero. I assume once you change the position, the object leaves it's parent? I reparented in code with similar results.. . how do you otherwise suggest moving objects. within a prrefab?
Well, GameObject.FInd is not good to use to begin with, but we'll forego that. Moving a child isn't going to unparent it. But keep in mind, the prefab is not what is in your scene. That is basically an instance of a prefab, or a clone. In this way, modifying the object in your scene doesn't change your prefab, so you could create several monsters for example and just modify the one you want to change. With your code, if you have an object ChildObjectFoundInPrefab and it's a child, the inspector should show you local position and not the position, so a position of 0 isn't going to show you a local position of 0. That all to say. Perhaps explain what you are trying to do a bit more as changing local position to Vector3.zero will move the child right onto the parent if that is what you want, but I'm unsure what you are trying to accomplish.
transform.position is world position, but for a child object the inspector will tell you its position relative to its parent. To adjust that in code you use transform.localPosition.