I have two groups of objects: an animated one, and a non animated one. Both are identical in structure and my goal is to make each object in the non animated group welded to their respective counterpart in the identical animated group.
I am currently simulating this by updating the objects every frame in Update() to match their moving counterpart, but It’s incredibly taxing on the engine. I’m trying to go for something that emulates the effect you get from a “parent child” relationship between transforms, only I need to keep them separate. Does a “Weld object A to always be relative to object B without parenting” method exist?
This is the sort of thing I would do, in a controlling script that manages connections between objects and counterparts:
struct WeldConnection {
GameObject parent;
List<GameObject> children;
}
List<WeldConnection> Connections = new List<WeldConnection>();
void Update() {
foreach (WeldConnection connection in Connections) {
foreach (GameObject child in connection.children) {
child.transform.position = connection.parent.transform.position;
}
}
}
Even though its basically what you’re doing already. Also, this sort of thing isn’t that taxing on Unity. In fact, its one of the simplest and fastest operations. Take a look at the profiler in Unity to see how much CPU is being used here. This is a relatively reliable method of doing this.
Also, why do you need to keep them separate? You can always change parents via transform.SetParent