Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Broken scripts with update 6 -> 7
#1
Had some issues with the update from Obi Rope 6 -> 7 in a project that used Obi Rope 6.  Luckily it's a scratch project.

1.  I tried upgrading on top of the old version but saw script errors so I removed all Obi files and installed fresh instead.  Of course, I have scripts and prefabs that depend on the older Obi files, so all of those break in the process of installation.  Even after the other issues were patched below, my existing code runs into Index Of Of Range errors on trying to load my existing rope blueprints, so now I have to see if it's a code issue or a blueprint schema change issue.  [Edit: I see the forum update guide says you have to regen blueprints.  I'm creating them from code, see below.]

2.  The demo scenes use a resource script called FPSDisplay.  It does not use a namespace, so it conflicted with another script I already had called FPSDisplay.  This caused compilation errors and breaks the script references in scenes that used either one (my existing scenes, as well as your demo scenes.)  Even after I added a namespace to my existing FPSDisplay, the script references were broken, so I had to add a namespace to your file and re-add it to the demo scene objects.  I thought Unity demanded all assets used namespaces to avoid this sort of conflict.  [Edit:  Similar breakage on SlowmoToggler which does not have a namespace (I have no such script but your demo scene had a broken link to it and Unity couldn't find it until I added one).]

3.  Many of your demo scenes use a built-in diffuse material for many objects.  Please define your own material for these objects, so that when I update all materials to URP these objects don't remain pink.

4.  There is no longer a type for ObiFixedUpdater.  I had a script that expected this type to force a regeneration of ropes (as I would deactivate and reactivate ropes in proximity to the player).  The CHANGELOG says all ObiUpdater types have been removed.  No guidance on what to do about scripts that referenced them.



Here is the code I'm trying to migrate.  It generates new blueprints on the fly during Start.

My prefab has four of these, and each one is spitting out Null Reference errors in your DrawGizmos in Edit mode.


Quote:NullReferenceException: Object reference not set to an instance of an object
Obi.ObiRopeCursorEditor.DrawGizmos (Obi.ObiRopeCursor cursor, UnityEditor.GizmoType gizmoType) (at Assets/Plugins/Obi/Editor/RopeAndRod/ObiRopeCursorEditor.cs:75)

Once I try running, I get Index Out Of Bounds errors in your ObiActor.LoadBlueprintParticles, when I provide the generated blueprint to ObiRope.  One error per rope, with different starting index numbers.


Quote:IndexOutOfRangeException: Writing to index 0 is out of range of '0' Capacity.
Obi.ObiNativeList`1[T].set_Item (System.Int32 index, T value) (at Assets/Plugins/Obi/Scripts/Common/DataStructures/NativeList/ObiNativeList.cs:98)
Obi.ObiActor.LoadBlueprintParticles (Obi.ObiActorBlueprint bp) (at Assets/Plugins/Obi/Scripts/Common/Actors/ObiActor.cs:995)
Obi.ObiActor.LoadBlueprint (Obi.ObiSolver solver) (at Assets/Plugins/Obi/Scripts/Common/Actors/ObiActor.cs:1161)
Obi.ObiRope.LoadBlueprint (Obi.ObiSolver solver) (at Assets/Plugins/Obi/Scripts/RopeAndRod/Actors/ObiRope.cs:187)
Screenplay.TightRope.Generate () (at Assets/__SHARED__/Scripts/For/Obi/TightRope.cs:109)
Screenplay.TightRope.Start () (at Assets/__SHARED__/Scripts/For/Obi/TightRope.cs:45)




Code:
// TightRope.cs
//
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Assertions;

using Obi;

namespace Screenplay
{
    //
    // Combines the logic of Obi's RopeBetweenTwoPoints and ObiRopeReel
    // to form a simulated rope between any two transforms, with managed slack.
    //
    public class TightRope: MonoBehaviour, ICraneRope
    {
        public ObiSolver solver;
        public ObiRopeCursor cursor;
        public ObiRope rope;

        public Transform start;
        public ObiParticleAttachment startAttachment;
        public Transform end;
        public ObiParticleAttachment endAttachment;

        public const float MINIMUM_SLACK = 0.0f;
        public const float MAXIMUM_SLACK = 1.0f;
        [Range(MINIMUM_SLACK, MAXIMUM_SLACK)]
        [Tooltip("How much additional length beyond distance from start to end")]
        public float slack = 0.1f;

        [Tooltip("How much change in length required to recalculate rope")]
        public float deltaLength = 0.05f;

        public float cursorMu = 0.5f;
        public float sourceMu = 0.95f;

        private float priorLength = float.NegativeInfinity;

        void Start()
        {
            Generate();

            // the rope actor must be a child under a solver to start the simulation
            transform.SetParent(solver.transform);
        }

        // ICraneRope
        public float GetLength()
        {
            if (priorLength > 0f)
                return priorLength;
            return IdealLength();
        }

        public float GetMaximumSlack() => MAXIMUM_SLACK;

        private float IdealLength()
        {
            float taut = start.Distance(end);
            if (slack < MINIMUM_SLACK)
                slack = MINIMUM_SLACK;
            return taut + slack;
        }

        public void Generate()
        {
            if (start == null || end == null)
                return;

            // Adjust our transform:
            transform.position = start.position;
            transform.rotation = start.rotation;

            // Calculate control point positions and tangent vector:
            Vector3 startPositionLS = transform.InverseTransformPoint(start.position);
            Vector3 endPositionLS = transform.InverseTransformPoint(end.position);
            Vector3 tangentLS = (endPositionLS - startPositionLS).normalized;
            Vector3 normalLS = start.right;

            // Add rope actor / renderer / attachment components:
            rope = gameObject.GetComponent<ObiRope>();
            rope.ropeBlueprint = null;

            // Create the blueprint:
            ObiRopeBlueprint clone;
            clone = ScriptableObject.CreateInstance<ObiRopeBlueprint>();
            clone.resolution = 0.5f;

            // Build the rope path:
            int filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0);
            clone.path.AddControlPoint(
                startPositionLS, -tangentLS, tangentLS, normalLS,
                0.1f, 0.1f, 1, filter, Color.white, "start");
            clone.path.AddControlPoint(
                endPositionLS, -tangentLS, tangentLS, normalLS,
                0.1f, 0.1f, 1, filter, Color.white, "end");
            clone.path.FlushEvents();

            // Generate particles/constraints:
            clone.GenerateImmediate();

            // Set the blueprint:
            rope.ropeBlueprint = clone;
            rope.LoadBlueprint(solver);

            cursor = gameObject.GetComponent<ObiRopeCursor>();

            // Attach both ends:
            startAttachment.target = start;
            startAttachment.particleGroup = clone.groups[0];
            endAttachment.target = end;
            endAttachment.particleGroup = clone.groups[1];
        }

        // Update is called once per frame
        void Update()
        {
            // get ideal rest length:
            float restLength = IdealLength();

            // if we haven't changed sufficiently, don't disturb it
            if (Mathf.Abs(restLength - priorLength) < deltaLength)
                return;

            cursor.cursorMu = cursorMu;
            cursor.sourceMu = sourceMu;
            cursor.UpdateCursor();

            // set the new rest length:
            cursor.ChangeLength(restLength);
            priorLength = restLength;
        }
    }

}
Reply
#2
(21-12-2024, 10:35 AM)hariedo Wrote: Had some issues with the update from Obi Rope 6 -> 7 in a project that used Obi Rope 6.  Luckily it's a scratch project.

1.  I tried upgrading on top of the old version but saw script errors so I removed all Obi files and installed fresh instead.  Of course, I have scripts and prefabs that depend on the older Obi files, so all of those break in the process of installation. 

Hi!

You can't install Obi 7 on top of a pre-existing Obi 6 installation, doing so will cause multiple compilation errors due to missing files/newly added ones. You must delete the /Obi folder and do a fresh install as explained in the upgrade guide.

Upgrading will require updating all your scripts and prefabs as warned in the manual. Several systems in Obi are now asynchronous (for instance, ObiRopeCursor) so scripting logic changes quite a bit. It's not a quick process. You should evaluate whether it's necessary for you to upgrade your project or stay on Obi 6, and maybe try 7 on upcoming projects.

(21-12-2024, 10:35 AM)hariedo Wrote: Even after the other issues were patched below, my existing code runs into Index Of Of Range errors on trying to load my existing rope blueprints, so now I have to see if it's a code issue or a blueprint schema change issue.  [Edit: I see the forum update guide says you have to regen blueprints.  I'm creating them from code, see below.]

There's been some changes to the scripting API as well, see the guide above.

(21-12-2024, 10:35 AM)hariedo Wrote: 2.  The demo scenes use a resource script called FPSDisplay.  It does not use a namespace, so it conflicted with another script I already had called FPSDisplay.  This caused compilation errors and breaks the script references in scenes that used either one (my existing scenes, as well as your demo scenes.)  Even after I added a namespace to my existing FPSDisplay, the script references were broken, so I had to add a namespace to your file and re-add it to the demo scene objects.  I thought Unity demanded all assets used namespaces to avoid this sort of conflict. 

Thanks for reporting this! FPSDisplay does not indeed have its own namespace, could find a few other sample scripts that don't either. Will fix this in the next update.

(21-12-2024, 10:35 AM)hariedo Wrote: [Edit:  Similar breakage on SlowmoToggler which does not have a namespace (I have no such script but your demo scene had a broken link to it and Unity couldn't find it until I added one).]


This component is used in the "RopeAndJoints" scene, and it is added to the ObiSolver component. Just downloaded the asset fresh from the store  but could not find any missing references/broken links to SlowmoToggler. Unity's asset verification process does not report any either.


(21-12-2024, 10:35 AM)hariedo Wrote: 3.  Many of your demo scenes use a built-in diffuse material for many objects.  Please define your own material for these objects, so that when I update all materials to URP these objects don't remain pink.

Diffuse materials should also be picked up by Unity's auto-updater. Most of the objects in the scenes just use the Standard shader.

(21-12-2024, 10:35 AM)hariedo Wrote: 4.  There is no longer a type for ObiFixedUpdater.  I had a script that expected this type to force a regeneration of ropes (as I would deactivate and reactivate ropes in proximity to the player).  The CHANGELOG says all ObiUpdater types have been removed.  No guidance on what to do about scripts that referenced them.

See the upgrade guide for details on what to do:

Quote:In Obi 7, all ObiUpdater components have been removed. ObiSolvers now update themselves at the right time, automatically parallelizing work with other solvers in the scene. You should open up your scenes/prefabs and remove missing references to these components:

-ObiFixedUpdater
-ObiLateFixedUpdater
-ObiLateUpdater

The substeps parameter in the updaters has been moved to the ObiSolver component. It is important that you adjust the amount of substeps in your ObiSolver to match the value your ObiUpdater was using, as too many substeps can have a large impact on performance.



Quote:Here is the code I'm trying to migrate.  It generates new blueprints on the fly during Start.

My prefab has four of these, and each one is spitting out Null Reference errors in your DrawGizmos in Edit mode.

Once I try running, I get Index Out Of Bounds errors in your ObiActor.LoadBlueprintParticles, when I provide the generated blueprint to ObiRope.  One error per rope, with different starting index numbers.

Will try your script and get back to you asap. At a first glance, the cursor related code acts as if the change in length is immediate - which no longer is - so it will likely break.

kind regards,
Reply
#3
Quote:In Obi 7, all ObiUpdater components have been removed. ObiSolvers now update themselves at the right time, automatically parallelizing work with other solvers in the scene. You should open up your scenes/prefabs and remove missing references to these components:

-ObiFixedUpdater
-ObiLateFixedUpdater
-ObiLateUpdater


Yes, I saw that.  I had an editor script that would seek them out and ensure they were added to the solver, so that I could then seek out and .Generate all the dynamically created ropes at edit time.  If we can fix my TightRope script above, then I think we're okay.


Quote:You should evaluate whether it's necessary for you to upgrade your project or stay on Obi 6, and maybe try 7 on upcoming projects.


As mentioned at the top of the thread, this IS evaluating 7 on a scratch project.  That doesn't mean I want to just throw out useful mechanisms that I have set up in my library of scripts and prefabs.  I also am considering buying the last Obi asset, Softbody, and am not going to attempt to have Obi 6 Rope for compatibility and Obi 7 Softbody in the same project.


Quote:Diffuse materials should also be picked up by Unity's auto-updater. Most of the objects in the scenes just use the Standard shader.


There are two "auto-updaters" in Unity.  One goes through the whole project looking for stuff to mangle, and one just updates the selected materials in the selected folder.  There's no middle ground to just update scenes in the Obi sample folder.  If your demo scenes don't rely on BiRP materials, then updating materials in the Obi folder would be sufficient.  Just a suggestion on how to make your asset bulletproof.
Reply