Obi Official Forum
Bug / Crash Obi Rope Prefab Pluger not working - 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: Bug / Crash Obi Rope Prefab Pluger not working (/thread-4334.html)



Obi Rope Prefab Pluger not working - PRodi - 19-08-2024

Hi,

I’m using Unity 2022.3.42f1, and my project is built with URP. After freshly downloading and installing Obi Rope into my project, I encountered some errors/bugs:
In your "ElectricalWires" scene, when I copy the Obi Solver in the Hierarchy or create a new prefab from the Obi Solver and try to use it in the same scene, I encounter the following errors after pressing the play button:

NullReferenceException: Object reference not set to an instance of an object
Obi.ObiRopePrefabPlugger.OnEnable () (at Assets/Obi/Scripts/RopeAndRod/Utils/ObiRopePrefabPlugger.cs:27)

(The same issue occurs if I try to duplicate any of the Obi Ropes multiple times in the scene hierarchy. Some instances work fine, and I can see sparks after tearing apart cables, but others generate these errors.)

I would like to use this as a prefab in my other game levels.

Can you please assist me in resolving this error?

Thank you for your help.


RE: Obi Rope Prefab Pluger not working - josemendez - 19-08-2024

Hi!

Thanks for reporting this! The prefab plugger sample script accesses the smoother's "actor" property in OnEnable(), however the smoother also sets its "actor" property during its own OnEnable().

Since the order in which Unity calls events for different components is undefined by default, this may sometimes cause trouble when the prefab plugger's OnEnable is called before the smoother's.

Replace line 27 of ObiRopePrefabPlugger.cs with this:
Code:
GetComponent<ObiActor>().OnInterpolate += UpdatePlugs;

instead of:
Code:
smoother.actor.OnInterpolate += UpdatePlugs;

This will ensure it works regardless of the update order Unity decides to use.

kind regards,


RE: Obi Rope Prefab Pluger not working - PRodi - 19-08-2024

Thank you so much this works like a charm now Gran sonrisa