Trying to create a Parent Constraint at runtime but it doesn’t seem to work, the child it not inheriting the source movement. The child object is locked and cannot be moved but that as far as it goes.
I can build it in the editor at run time, add a parent constraint in the inspector then add a source and it works but it doesn’t seem to work when done with code, is there something I’m missing?
below is a simple example that doesn’t work but should?
https://stackoverflow.com/questions/56039340/unity-how-add-source-on-runtime-to-parentconstraint
using UnityEngine;
using UnityEngine.Animations;
public class ParentTest : MonoBehaviour
{
ConstraintSource constraintSource;
void Start()
{
var go = new GameObject("Source");
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
var parentConstraint = cube.AddComponent<ParentConstraint>();
constraintSource.sourceTransform = go.transform;
parentConstraint.AddSource(constraintSource);
parentConstraint.constraintActive = true;
}
}
any help on how to get this working/what is missing or conformation that it doesn’t work would be very much appreciated.
Many thanks