Stored Child transform variable does not update - unity3d

I have a unity game where I have a bunch of objects that are children of the player object. So when the player runs around, the children objects also run around relative to the player.
At the beginning of the game, I have a transform variable that stores the transform of one of the child objects, then i use that transform variable for the rest of the game to have the enemies use that to chase the children.
Transform childTransform=GameObject.Find("Parent").FindInChildren("child_1").transform;
But it seems this variable that points to the child transform, doesnt get updated to the current value when the parent moves. It just stays in the original position when i assigned it, so the enemy dont follow the current position, it just stays at the original position.
Maybe my code is wrong?
I thought it would get updated automatically to be the world space value of the child relative to the parent.
Anybody knows why? Do I have to constantly look up the child and reassign the variable each Update()? Isnt that a waste of CPU time?
Thanks

Related

My prefabs' size appears wrong when placed

So on a game I am working on, I keep having the same problem where whenever I turn an object into a prefab, somehow the object always appears smaller but the width and height says otherwise. I can't seem to fix this problem and it also applies whenever I try to instantiate it, it always remains that way even when I just create a prefab.
The Prefab as an example
The image I screenshot shows what happens whenever I assign or make an object as a prefab. Am I doing something stupid? or is it just because there is a setting I am not aware of?
In unity ths scale of an object affected by it's parent scale..
so for example if I have a cube with width 10 unit and it is scale is [10,1,1]
and I convert it to prefab every time Iniciate object from it will be in the same scale..
the problem apper if my cube was a chiled for other game object with scale for example [5,5,5]...
as you see in this picture
this is the same prefab but the size is totaly diffrent because of the parent
to avoid this proble be sure always to make your prefab with scale 1 1 1
you can create an empty game object with scale 1 1 1 and position[0,0,0] then make your object child of it then make your prefab ...
:) and if you want further help pleace give more specific informations for your problem

Get Orientation of SCNNode Swift [duplicate]

I am working on a basic racing game using Apple's SceneKit and am running into issues simulating a car. Using the SCNPhysicsVehicle behavior, I am able to properly set up the car and drive it using the documented methods.
However, I am unable to get the car's position. It seems logical that the SCNPhysicsVehicle would move the SCNNodes that contain the chassis and the wheels as the car moves but the SCNNodes remain at their original position and orientation. Strangely enough, the chassis' SCNPhysicsBody's velocity remains accurate throughout the simulation so I can assume that the car's position is based off of the SCNPhysicsBody and not the SCNNode. Unfortunately, there is no documented method that I have found to get an SCNPhysicsBody's position.
Getting a car's position should be trivial and is essential to create a racing game but I can't seem to find any way of getting it. Any thoughts or suggestions would be appreciated.
Scene Kit automatically updates the position of the node that owns an SCNPhysicsBody based on the physics simulation, so SCNNode.position is the right property to look for.
The catch is that there are actually two versions of that node in play. The one you typically access is called the "model" node. It reflects the target values for properties you set, even if you set those properties through an animation. The presentationNode reflects the state of the node currently being rendered — if an animation is in progress, the node's properties have intermediate values, not the target values of the animation.
Actions, physics, constraints, and any scene graph changes you make inside update/render loop methods directly target the "presentation" version of your scene graph. So, to read node properties that have been set by the physics simulation, get the presentationNode for the node you're interested in (the node that owns the vehicle's chassisBody physics body), then read the presentation node's position (or other properties).
I have the same problem with my player node.
I move it with applyForce (to manage collision detection).
But when i check node position after some movement, the node position has not move (presentation node is the actual position as rickster write in his answer)
I manage to update the scnNode.position with renderer loop
You have to set position of your node with the presentationNode position.
node.position = node.presentationNode.position
Set this into renderer(_: updateAtTime) and your node position will sync with any animation you made to the physicsBody

Unity Gameobject is far away from the Move Tool

why is my Gameobject so far away from the Move Tool as you can see in the Picture down below?
I would like to have it centered at the Gameobject. How can I change this?
GameObject away from Move Tool
Screenshot of Hierarchy
Check the object in the scene hierarchy and make sure that the transform eg. x,y,z are set to 0.
If your object is a child of another object and they are not at the same position you are probably moving the parent and not the child object itself.
that Move Tool is the objects origin, and this might help:
"The easiest way is to create an empty object as a parent object. Then you put the corridor object as a child of the empty object. You can then alter the position of the corridor object so its positioned at the edge.
i found your answer here
note that its not exact, in your case, make an empty object, move it to where you would like your origin or move tool THEN add your other object to it as a child. you can then move it with the parents move tool(origin) right on top of your box.

Swift SKSpriteNode: Complex Sprite Textures?

This is a question regarding best-practice for implementation. For an example, I will reference a simple game called Pixel Claw.
Suppose I had an SKSpriteNode akin to the claw from Pixel Claw, in that what the SKSpriteNode might be ''holding'' is variable (but finite in possibilities, e.g. four different objects).
What the node SKSpriteNode is holding has no agency of itself.
Thus my question is: is it better to use different textures such as a claw, a claw holding object a, a claw holding object b, etc or have two SKSpriteNodes and position the SKSpriteNode with the claw texture to be next to the SKSpriteNode with an object texture?
I am not making a claw game, it was just the first example that popped to my head where both could be plausible solutions. The former being more simplistic - just switch the texture, the latter being more generalizable.
If the latter is the best solution all around, how can one ''pair'' the movements of the two sprites?
I would use the second approach especially if the objects a and b can fall out of the claw at some point.
You should make the texture of a claw, the texture of object a, and the texture of object b.
To make the objects move in sync with the claw, simply add the object as a child of the claw node. This way, moving the claw will cause the object to move as well!
Note that before adding the object as a child, you need to make sure that the object does not have a parent. If it does, you must remove it from its parent before adding it as a child of the claw. The same thing applies when you "release" the object from the claw: you need to first remove the object from its parent (the claw) and then add it as a child of the desired parent.

Unity3d Transform issues when trying to re-parent a Gameobject with sub-Gameobjects

I am trying to grab a Gameobject that's placed in the correct spot and re-parent it to different Gameobject transforms using code. I manage to do this by using ..transform.parent = parent.transform but the rotation and position get messed up. How can I keep it's rotation and position when re-parenting?
Thanks!
Always use gameObject.transform.SetParent(anotherGameObject), or you risk exactly the sort of phenomena you've described. See SetParent docs; there is a second parameter to consider.
The form mentioned in the question still works in many cases, but has been deprecated for a while.
Place all game object that you want to parent, to empty game object(example:"EMPTY\PARENT\EMPTY\CHILD") with scale 1:1:1(in editor)or re-scale your parent game object to 1:1:1