Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Make a change to ContentSizeFitter.cs

Discussion in 'Scripting' started by realragnvaldr, Apr 23, 2022.

  1. realragnvaldr

    realragnvaldr

    Joined:
    Jul 21, 2019
    Posts:
    40
    (The original post was about ContentSizeFitter.cs, but I realized that I actually need to modify ScrollRect.cs -- but that doesn't really change my question)

    I would like to add a NaN check somewhere in ScrollRect.cs, as a possible solution to this problem).

    The problem i have is that the ScrollRect.cs file is in the packagecache folder, which is read-only, meaning that any changes i make are automatically undone.

    I got around this by copy-pasting the code of ScrollRect into a new script MyScrollRect.cs. This works, but I wonder if there is a better/easier way to make this change. One minor disadvantage is that I now manually will have to replace every ScrollRect in my app with MyScrollRect - it would be nice if there is a solution that avoids this step.
     
    Last edited: Apr 23, 2022
  2. Dextozz

    Dextozz

    Joined:
    Apr 8, 2018
    Posts:
    488
    About manual replacement
    Since this is an issue you'll have to face in the feature, even outside of this current problem, it's best to mention it first. If you open your .prefab files or .unity (scene) files in a text editor, you'll see they all have a UUID near the top. That's the unique ID of that specific component type. Unity's scroll rect has a unique ID that is added to all objects that have that component; so does your own wrapper script.

    Once you've identified the unique ID of your script and the unique ID of Unity's Scroll Rect component, you can use anything with a find and replace to swap those two values across all prefabs and scenes. It's really quick to do and there are no worries about forgetting something.

    About copy-ing the entire scroll rect
    Uf, that's tough. You're lucky it's a UI bug and that that code is open source. If it was anything else, you'd be screwed. I don't really have any proper advice as I haven't faced this before, other than submitting a bug report to Unity and maybe asking them. Maybe you could implement a callback on when you set the scaled time to 0 and stop all scrolling that's currently happening?
     
    realragnvaldr likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,717
    I use this manual behind-the-scenes GUID swap technique moderately frequently, perhaps twice a year. It works gloriously well, but I do not recommend trying it unless you are fully and properly source-controlling your project.

    With source control you can see the diffs for the changes you make as well as roll back any inadvertent damage or confusion that might occur.
     
    realragnvaldr likes this.
  4. realragnvaldr

    realragnvaldr

    Joined:
    Jul 21, 2019
    Posts:
    40
    Yes, I realized I was lucky, which is why i thought i better ask :) Many thanks for your fast and constructive reply! I'll try the UID approach next time.

    As for the bug, I managed to fix it and have written a separate post on it - hopefully they'll fix it.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,717
    realragnvaldr likes this.