Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug / Crash  Obi Rope Prefab Pluger not working
#1
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.
Reply
#2
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,
Reply
#3
Thank you so much this works like a charm now Gran sonrisa
Reply