![]() |
Help Add constraint following hook example - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html) +--- Thread: Help Add constraint following hook example (/thread-2550.html) |
Add constraint following hook example - flaurens - 20-10-2020 I'm following the RopeGrapplingHook example in order to achieve a similar example but with already created ropes. So my idea is that when I press a certain button a constraint is created between the rope and the player: Code: public ObiRopeBlueprint m_ActualBlueprint; But when I press the button I get the following error: NullReferenceException: Object reference not set to an instance of an object Obi.ObiPinConstraintsBatch.AddConstraint (System.Int32 index, Obi.ObiColliderBase body, UnityEngine.Vector3 offset, UnityEngine.Quaternion restDarboux) (at Assets/10-Vendors/Obi/Obi/Scripts/Common/Blueprints/Constraints/Batches/ObiPinConstraintsBatch.cs:82) LianasTest.AddConstraint () (at Assets/10-Vendors/Obi/Obi/Scripts/RopeAndRod/Utils/Temporal/LianasTest.cs:26) LianasTest.Update () (at Assets/10-Vendors/Obi/Obi/Scripts/RopeAndRod/Utils/Temporal/LianasTest.cs:17) I assume that I'm doing something wrong, I have checked the batch var and it's not null so I'm not really sure what is the problem with AddConstraint. PS: I made the following modification: Code: //var pinConstraints = m_ActualBluePrint.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch> I read that blueprint acts as a prefab so in runtime cant be modified. Now I'm not getting any error but the constraint isn't happening anyway. Regards! RE: Add constraint following hook example - josemendez - 21-10-2020 Hi there, Asumiría, por el nombre de tu script ("Temporal/LianasTest"), que eres hispanohablante. Yo soy español, si prefieres podemos hablar por correo en español ![]() Blueprints behave like prefabs indeed: they're used to instantiate particle/constraint data into the scene (in the form of a ObiActor, such as a rope), but the original blueprint data is not tied to existing instances. If you modify blueprint data, existing actors won't be affected. Only actors that you create from them on will "inherit" the changes made on the blueprint. So your second attempt is the correct one. There's 2 important things missing from your script: - You're not activating the constraints. - You're not telling the actor to rebuild constraint batches. (Obi 5.6 and up only) The correct code (in Obi 5.6) would be: Code: var pinConstraints = rope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>; Also, check that pin constraints are globally enabled in your solver. |