Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice
Unity's version control component has been upgraded to Plastic SCM.

[Solved] Issue with .asset files updating through Collab

Discussion in 'Unity Collaborate' started by Maccu87, Feb 22, 2017.

  1. Maccu87

    Maccu87

    Joined:
    Jan 15, 2016
    Posts:
    3
    I have noticed this has happened a couple of times now. When publishing changes from one system and pulling .assets created from scriptableobjects down onto another, the changes are not correctly updated. Sometimes it seems to create the required amount of items in the list but does not populate the values correctly?

    Anyone else experienced this?
     
  2. Ryan-Unity

    Ryan-Unity

    Joined:
    Mar 23, 2016
    Posts:
    1,993
    Hi @Maccu87! Could you go into a little more detail about the issue you're seeing? With regards to the items in the list, are those items in a custom .assets file or in the Collab Toolbar? Can you submit a bug from this project with steps on how to to repro this behavior?
     
  3. Maccu87

    Maccu87

    Joined:
    Jan 15, 2016
    Posts:
    3
    So I have created a ScriptableObject for some items like so:
    Code (CSharp):
    1. public List<ItemData> Items;
    and using [CreateAssetMenu] to be able to create an asset out of the ScriptableObject. After populating the asset with data, such as filling out the 'ItemData' with name, type etc, if I commit the changes, and pull them down on another machine, the changes to the .asset file do not seem to have been pushed/pulled. A friend of mine is experiencing a similar issue to this. I have found it to actually cause the entire asset to be wiped out of data once too. I hope this makes more sense?
     
  4. Ryan-Unity

    Ryan-Unity

    Joined:
    Mar 23, 2016
    Posts:
    1,993
    Gotcha. Thanks for the quick reply. This bug will be fixed in the latest 5.6 beta.

    In the meantime, could you try refreshing your ScriptableObject by going into the Project Window, right-clicking on the script then clicking "Refresh"? If it's the same bug that was just fixed then doing that should resolve your issue. If not then could you report a bug with your project?
     
  5. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    767
    We're having a problem similar to this. This is what we are seeing:

    1. Two team members, both editing the same .asset (scriptableobject) file.
    2. My teammate pushes changes.
    3. I pull the commit but receive no merge conflict warning. It appears the file is partially overwritten/merged. Some fields are changed but not all, and no idea how it's picking which to merge. The icon in the project window still indicates that I need to push the asset file / I have made changes to it.
    4. Now I'm afraid to push my commit, since I have no idea if my teammate's version of the file will be overwritten/changed.

    We are using Unity 5.5 - is there a reason why fixes can't be propagated to 5.5? We really love Collaborate, it has made version control and collaboration so much easier for us, so it'd be great to get new fixes/features for 5.5. Any ideas what we can do?

    Thanks!

    EDIT:

    Just saw that I'm getting this warning message in the console:

    "Someone else also changed '**NameOfAsset**'. The changes were merged and a backup of your original file was copied to '**FileLocation**'"

    I compared the two versions and it's clear that collaborate is "smartly" merging the two files.
    But what we really want is for Collaborate to warn us before we pull the file, like it does with other file, instead of just deciding by itself to back up and merge the two versions. That way, at least we know and can choose what we want to happen. Is there anyway to change the default behaviour to force a merge conflict message?
     
    Last edited: Apr 26, 2017
  6. Ryan-Unity

    Ryan-Unity

    Joined:
    Mar 23, 2016
    Posts:
    1,993
    Hi @flashframe! Thank you for letting us know about these issues. Asset files from ScriptableObjects currently do not auto-merge as intended. A bug has been filed and we hope to address this issue in the future.

    In the meantime, I would recommend that only one of you work on a .asset file generated from a ScriptableObject at a time. If you push what changes you have in your .asset file now then your teammate will get the same changes if they don't have any local changes on that file. If your teammate does, though, then there's a chance that their changes will get overwritten or duplicated. I'm very sorry about this and hope that you two don't lose too much work over this.

    As far as backporting fixes goes, I'm very happy to hear that you both love Collaborate so much and we want to keep making it better for users like you, both by making these kinds of fixes and by adding more cool, useful features. Unfortunately, we don't have enough time in the day to do all that AND backport non-critical bug fixes to earlier versions :(. I understand that upgrading to new versions isn't always an option for some teams and know all too well how frustrating it is when a bug fix you really want doesn't make it into a patch for an earlier version. But we really appreciate your patience with us and hope that you'll continue to use Collaborate as well as let us know when something doesn't work right.
     
  7. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    767
    Hi @ryanc-unity

    Thanks for the reply :)

    We've decided the best approach is to split up our asset file into smaller "per scene" assets - which fits in with the workflow of not editing the same scene concurrently, while still allowing us both to edit parts of the data set.

    I understand and sympathise regarding lack of time! We are just at a point in our game that updating Unity versions is a real headache. Everything has a cost :-(

    Collaborate is great though, and other than this issue it has worked out really well for us, so thank you for the work you and your team are doing.
     
    Ryan-Unity likes this.
  8. zeb33

    zeb33

    Joined:
    Nov 17, 2014
    Posts:
    95
    Hi. we seem to be having same issue with unity 2017.2.f03. Is there still an issue with collab and ScriptableObject?
     
  9. Ryan-Unity

    Ryan-Unity

    Joined:
    Mar 23, 2016
    Posts:
    1,993
    Hi @zeb33! I'm sorry to hear that you're running into this issue. Can you go into more detail on when you're seeing this issue? Are you and a teammate editing a ScriptableObject at the same time and trying to merge your changes?
     
  10. Arkas000

    Arkas000

    Joined:
    Jun 9, 2013
    Posts:
    1
    Hello @ryanc-unity I've the same issue with 2017.2. I'm the only person of the team that edits the ScriptableObjects. Pushing the changes doesn't seem to affect the values of the scriptableObjects. If I try to change an int value for example and then push it, then the updated value doesn't arrive to my team.
     
  11. Ryan-Unity

    Ryan-Unity

    Joined:
    Mar 23, 2016
    Posts:
    1,993
    Hi @Arkas000! Do you happen to have a small sample project that you would be willing to share that reproduces this bug? It would really help us out in coming up with a fix for it. Not everyone on the team is super familiar with ScriptableObjects so the more real life examples we can look through to test a fix against, the better.

    You could either submit your sample project using Unity's Bug Reporter and forward me the bug number or you could DM me your sample project's UPID and I can make a copy of it to test with.
     
  12. oakshiro

    oakshiro

    Joined:
    Dec 9, 2008
    Posts:
    20
    Still happens on 2017.2.0f3. We have to be super carefully and delete + revert the scriptableobjects anytime one of our teammates modify them.
     
  13. Ryan-Unity

    Ryan-Unity

    Joined:
    Mar 23, 2016
    Posts:
    1,993
    @oakshiro that's terrible! Would you mind submitting a sample project with repro steps via the Bug Reporter? It would help us a great deal in finding a fix for this issue.
     
  14. oakshiro

    oakshiro

    Joined:
    Dec 9, 2008
    Posts:
    20
    Ok, I'll submit it as soon as I can.
     
  15. Ryan-Unity

    Ryan-Unity

    Joined:
    Mar 23, 2016
    Posts:
    1,993
    Thank you! Be sure to post here or send me a DM with the bug number once it's been emailed to you so that I can quickly look it up on my end.
     
  16. Nayrutes

    Nayrutes

    Joined:
    Dec 7, 2017
    Posts:
    1
    I thought I had the same bug but I didn't save my asset (ScriptableObject) properly.
    Calling EditorUtility.SetDirty(myScriptableObject) and AssetDatabase.SaveAssets() after editing values did the trick for me.
     
  17. DanVioletSagmiller

    DanVioletSagmiller

    Joined:
    Aug 26, 2010
    Posts:
    203
    I'm also having this issue (2017.3.0f3). However, I do not have a custom editor. When I have a custom editor, I have the power to say "SetDirty" and that works. but this is the default behaviour of the inspector. :( I'm submitting my project...
     
  18. PedroGV

    PedroGV

    Joined:
    Nov 1, 2010
    Posts:
    415
    The problem that I'm having is that the SOs is correctly persisted in Collaborate from a PC with Windows, but as soon as I download it into a MacOSX, some of the SOs do not retrieve the values from Collaborate so they are created with default values. And "revert" does not work because as soon as you press it, even though view changes do show the correct values on the remote file, those SOs are recreated on the MacOSX, again, with default values.

    Working with Unity 2017.1.4f1 in both machines.
     
  19. AlfieBooth

    AlfieBooth

    Joined:
    Dec 2, 2013
    Posts:
    31
    I'm having the same issue in 2018.2.15f1.
    I'm using collab between a windows and a mac machine. Collaborate registers the adding and removing of .asset SO's, and any name changes made. However any changes to the properties (in my case, one texture and a bunch of color values) are not registered, forcing me to update them manually on both machines. This is pretty annoying at the min, but eventually I will have 100+ of these .assets.

    Any help would be greatly appreciated.

    Alfie.
     
  20. Ryan-Unity

    Ryan-Unity

    Joined:
    Mar 23, 2016
    Posts:
    1,993
    Hi @AlfieBooth! Do you happen to have a small sample project with just your .asset SO's that you'd be willing to share with us that we could use for testing? You can submit it to us either through the Unity Bug Reporter or when submitting a Support Ticket with us. Thank you in advance!
     
  21. AlfieBooth

    AlfieBooth

    Joined:
    Dec 2, 2013
    Posts:
    31
    Hi Ryan,
    Apologies for the delay. Yes of course. I'll get right on it. Thanks for your time.
    Alfie
     
    Ryan-Unity likes this.
  22. flipwon

    flipwon

    Joined:
    Dec 29, 2016
    Posts:
    179
    Wow, crazy to see that this has been an issue for so long. Same here, scriptable objects aren't registering all their changes between builds :(
     
  23. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    This is probably not the issue but just in case... You guys did confirm that your data serializes properly right? Certain types and custom types need extra work to serialize to an asset file. Datetime and guid are examples.
     
  24. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    724
    Its 2019, and it seems like this issue is returning with ScriptableObject.
    Has happened multiple times in recent few days..
     
  25. Ryan-Unity

    Ryan-Unity

    Joined:
    Mar 23, 2016
    Posts:
    1,993
    Hi @Gekigengar, I'm sorry you're running into this issue so often. Could you go into more detail to help us reproduce this issue? Which version of Unity 2019 were you using, what changed fields in your ScriptableObject don't seem to be syncing properly, how often do changes with your ScriptableObject seem to go missing? When you download the entire project on a new machine, do you see all of the changes there?
     
  26. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    724
    Using 2019.1.11f1, this has happened on both machine I am using (I switch back and forth between machines with Collab). I have already submitted a bug report a few days ago. Unfortunately, it is not always reproduce-able.

    The most recent occurrence is when I've added "Intelligence" struct to my scriptable object, and added some value to it. Though, I am not sure if it has anything to do with it. By the time I moved to the other machine, every system that requires the memory stats is broken. I later found that the issue is simply Unity not updating the scriptable objects assets, even if everything else is updated even when Collab says everything is up to date.

    Other scriptable objects were also not synchronized, as I've made changes to a few values for my LOItemData .asset files.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. namespace LightsOut
    6. {
    7.     [CreateAssetMenu(fileName = "New Base Character Stats Configuration", menuName = "LightsOut/Character/Base Character Stats Configuration", order = 1)]
    8.     public class BaseCharacterStatsConfiguration : ScriptableObject
    9.     {
    10.         public LOStats characterStats;
    11.     }
    12. }
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System;
    5.  
    6. namespace LightsOut
    7. {
    8.     [Serializable]
    9.     public class LOStats
    10.     {
    11.         public CharacterInformation Information;
    12.         public HealthStats Health;
    13.         public IntelligenceStats Intelligence;
    14.         public VisibilityStats Visibility;
    15.         public MovementStats Movement;
    16.         public InventoryStats Inventory;
    17.     }
    18.  
    19.     [Serializable]
    20.     public struct CharacterInformation
    21.     {
    22.         public string characterFirstName;
    23.         public string characterLastName;
    24.         public bool tryHookUI;
    25.     }
    26.  
    27.     [Serializable]
    28.     public struct HealthStats
    29.     {
    30.         public float baseMaxHP;
    31.         public float multiplierMaxHP;
    32.     }
    33.  
    34.     [Serializable]
    35.     public struct IntelligenceStats
    36.     {
    37.         public int baseMemoryLimit;
    38.     }
    39.  
    40.     [Serializable]
    41.     public struct VisibilityStats
    42.     {
    43.         public float baseVisibilityPriority;
    44.         public float baseVisibilityRate;
    45.         public float multiplierVisibilityRate;
    46.     }
    47.  
    48.     [Serializable]
    49.     public struct MovementStats
    50.     {
    51.         public float baseMS;
    52.         public float multiplierMS;
    53.     }
    54.  
    55.     [Serializable]
    56.     public struct InventoryStats
    57.     {
    58.         public int primarySlotCount;
    59.         public int secondarySlotCount;
    60.     }
    61. }
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. namespace LightsOut
    6. {
    7.     [CreateAssetMenu(fileName = "New Item Data", menuName = "LightsOut/Item Data", order = 1)]
    8.     public class LOItemData : ScriptableObject
    9.     {
    10.         #pragma warning disable 0649
    11.         [Header("Generic Stats")]
    12.         public string ItemName;
    13.         [SerializeField] private string _itemDescription;
    14.         [SerializeField] private ItemHandPosition _itemCarryType;
    15.         [SerializeField] private float _itemMaxDurability;
    16.  
    17.         [Header("Item Render")]
    18.         [SerializeField] private GameObject _modelPrefab;
    19.         [SerializeField] private Sprite _itemBTN;
    20.         [SerializeField] private Sprite _itemDISBTN;
    21.         #pragma warning restore 0649
    22.  
    23.         public string ItemDescription { get => _itemDescription; }
    24.  
    25.         public ItemHandPosition ItemCarryType { get => _itemCarryType; }
    26.  
    27.         public float ItemMaxDurability { get => _itemMaxDurability; }
    28.  
    29.         public GameObject ModelPrefab { get => _modelPrefab; }
    30.  
    31.         public Sprite ItemBTN { get => _itemBTN; }
    32.         public Sprite ItemDISBTN { get => _itemDISBTN; }
    33.  
    34.         // Default values of fields here.
    35.         public virtual void Reset()
    36.         {
    37.             ItemName = "New Item Data";
    38.         }
    39.     }
    40. }
     
  27. Ryan-Unity

    Ryan-Unity

    Joined:
    Mar 23, 2016
    Posts:
    1,993
    Thank you for sharing more info with me! I tracked down the bug you submitted around this issue (1177664) and will dig a little deeper into it to try to see if I can reproduce it on my end. By the "memory stats" you mentioned that would break, are you referring to the IntelligenceStats struct or to a different struct that was included in a different file? Roughly how many times out of 10 would you say that the sync issues happen when making changes around the ScriptableObjects?
     
  28. WLewis47

    WLewis47

    Joined:
    Jul 6, 2018
    Posts:
    4
    I'm having trouble with this, too. Very frustrating.

    For me, I'm having the bug with Color and Sprites.
    Code (CSharp):
    1. [SerializeField] Color posOpinionColor;
    2. [SerializeField] Color neutralOpinionColor;
    3. [SerializeField] Color negOpinionColor;
    4. [SerializeField] Sprite kingTitle;
    5. [SerializeField] Sprite dukeTitle;
    6. [SerializeField] Sprite earlTitle;
    The *.asset file actually does maintain its updates between collaborations (when I try to edit this to look proper in this post, it tells me it looks like I'm posting spam):
    posOpinionColor: {r: 0.18039216, g: 0.30980393, b: 0.18431373, a: 1}
    neutralOpinionColor: {r: 0.44705883, g: 0.40784314, b: 0.35686275, a: 1}
    negOpinionColor: {r: 0.54509807, g: 0.078431375, b: 0, a: 1}
    kingTitle: {fileID: 21300000, guid: 6fac473811e6eb942935790e15a155d4, type: 3}
    dukeTitle: {fileID: 21300000, guid: dc9311084bace4347b29329c7f5f902c, type: 3}
    earlTitle: {fileID: 21300000, guid: 574dbfda1d1374844b0eeb80d9dd2f1e, type: 3}


    But the ScriptableObject is not reflecting the data in the *.asset file:
    upload_2019-9-5_20-54-43.png

    I've tried refreshing and reimporting the *.asset, and the *.cs, but no dice.
     
  29. WLewis47

    WLewis47

    Joined:
    Jul 6, 2018
    Posts:
    4
    FWIW, I just found a fix!

    The *.asset file is adding an extra line to the very end of the file following collaboration. If I delete that line, it works. This is, of course, not ideal, and the problem will compound as the project goes, so it would be nice to get a real fix in.

    Not working:
    upload_2019-9-5_21-0-9.png

    Working:
    upload_2019-9-5_21-0-22.png
     

    Attached Files:

  30. ivanngoc

    ivanngoc

    Joined:
    Nov 9, 2018
    Posts:
    9
    Hi , evryone. Same problem here. Each time I modify Scriptable Object asset programmatic via editor script collab doesn't notice any difference. Scriptable object have OnValidate logic. And only when i change any field in editor window collab see the changes
    Unity 2019.2.6f1
     
  31. ivanngoc

    ivanngoc

    Joined:
    Nov 9, 2018
    Posts:
    9
    Solved my problem by using
    EditorUtility.SetDirty(obj);
    After that click File=>Save project.
    Only after that scriptable object .asset file has changed
     
    Gekigengar and Ryan-Unity like this.
  32. OwenG

    OwenG

    Joined:
    Sep 30, 2013
    Posts:
    20
    Hi, we're currently seeing the issue in 2019.1.14f1.

    Here's what we've found/tried...

    Cause and effect:
    - Dev 1 changes values in a ScriptableObject on their computer and saves
    - The asset changes are saved and committed to Git
    - Dev 2 has Unity open
    - Dev 2 pulls Dev 1's changes from Git
    - On Dev 2's computer, if the asset is opened in a text editor, we can see the changes that Dev 1 made
    - Dev 2 checks the ScriptableObject in Unity, but Unity does not load any of the asset changes

    E.g.
    A ScriptableObject has an int member called "count". It defaults to 0. Dev 1 sets it to 1 and commits. Dev 2 pulls and checks the SO in Unity, and count reads 0, even though count = 1 in the asset file itself.
    [EDIT: I would appear my simplified example doesn't hold true. What we're actually seeing is a problem that is maybe specific to List<> members. Ints seem to carry across fine. If Dev 1 adds elements to a list, saves, commits. Then Dev 2 pulls the changes, those changes will not appear in the list until the asset is changed on their local machine (or Unity is rebooted). This is for Lists of objects, but also for lists of ints/strings.]

    Note that this only occurs if Unity is open when the git pull is done. If Dev 2 closes and reopens Unity, the change will appear.

    We have tried:
    - Refreshing the asset
    - Reimporting the asset
    - Doing an AssetDatabase.ImportAsset with ImportAssetOptions.ForceUpdate set
    And nothing forces Unity to reload the asset properly.

    If we do the following:
    - Dev 2 pulls Dev 1's changes
    - Dev 2 makes a change to a value in the SO in Unity
    - Dev 2 saves their changes
    - In Git, Git detects the change but ALSO shows the change to the "count" variable as being reverted to 0 from 1
    - Now Dev 2 discards their changes in git and goes back to Unity
    - Unity NOW sees the changes properly.

    So it seems like when the asset is changed from git, Unity is not seeing that asset as something that needs to be deserialized again? But if we make changes on our local computer and set the file, Unity NOW knows that it needs to update the file.

    That's all the information we have. We have been unable to solve the problem aside from closing and reopening Unity every time we pull from git.

    Owen
     
    Last edited: Feb 25, 2020
  33. OwenG

    OwenG

    Joined:
    Sep 30, 2013
    Posts:
    20
    I was going to edit my post above, but thought it might be clearer to post a new thing.

    We've been investigating further and discovered that it's not actually specific to Lists. It can happen with ints and strings too. What we think is the issue is when something is added to the ScriptableObject for the first time.

    E.g.
    Say I have a ScriptableObject defined as such:

    Code (CSharp):
    1. public class MySO : ScriptableObject
    2. {
    3.     public int firstMember = 0;
    4. }
    I save the object and commit it to git. Now Dev 2 pulls my changes. Now I change the class:

    Code (CSharp):
    1. public class MySO : ScriptableObject
    2. {
    3.     public int firstMember = 0;
    4.     public int secondMember = 0;
    5. }
    And in the Unity inspector I change the value of secondMember to 2. Now I save and commit. Dev 2 pulls from git with Unity open and looks at the asset I pushed. Dev 2 will see an object with firstMember = 0, and secondMember = 0. But if Dev 2 looks at the asset in a text editor, secondMember will be 2.

    Once Dev 2 has a version of the asset correctly deserialized by Unity, then future changes to the value of secondMember will get detected. It's just that first time when it's added, as far as we can tell?

    Owen
     
  34. Ryan-Unity

    Ryan-Unity

    Joined:
    Mar 23, 2016
    Posts:
    1,993
    Thank you all for the additional feedback!

    The issue with ScriptableObjects not syncing their changes unless the Editor is restarted after a Collab Update appears to be fixed in 2020.1 with the Asset Importer Pipeline v2. We've looked into trying to backport a fix but because the issue lies with the Asset Importer rather than with Collab specifically, it falls outside of our team to tackle it.

    I apologize for the difficulty this sync issue has caused so many users and we will be strengthening our testing around this area to help prevent these types of bugs from happening again in future versions.
     
    Gekigengar likes this.
  35. BenWilles

    BenWilles

    Joined:
    Mar 9, 2018
    Posts:
    41
    How about fixing it for the current LTS?
     
    pistoleta likes this.
  36. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    2020.1 ? we have been waiting for the LTS for months so we can trust a long support on it and now you pretend to solve something like that on another version?
    I find it ridiculous sincerely. I don't know but since I updated to the last 2019 seems the synchronizations is getting even worse with my team.
     
  37. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    Anybody knows some workaround to keep the SO's well synchronized? does this happen also using GitHub ?
     
  38. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    We have this issue with Git. On disk on the hard drive it says it's changed, but GIT is not picking up the changes.
     
  39. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    Damn I was hoping Git would not have that problem, but does it happen always? I our case just happens once in a while
     
  40. tropezon

    tropezon

    Joined:
    Aug 8, 2017
    Posts:
    4
    In my experience with 20 people working in a project with git only happenend to one member, but occours all the time. 2019.4
     
  41. Martian-Games

    Martian-Games

    Joined:
    Jan 19, 2012
    Posts:
    44
    Still happens in 2020.1.7
    Making any change to a Scriptable Obj , Collab does not notice the change.
    I have to make copies of them and re-assign them to my prefabs everytime.
     
  42. laxersaz

    laxersaz

    Joined:
    Apr 20, 2019
    Posts:
    5
    We have the same problem with version 2021.1.6
    Everytime on of us pulls the changes via collaborate, scriptable objects may be updated correctly, not at all or even completely destroy them.
    This is very frustrating.
     
  43. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    Happened to us last week with 2020.3.7, but we think its because one of us had 2020.3.1 and maybe working with different versions caused the problem.
    I've been told problems like these don't happen at all using Git, but someone said on this thread it happens also.
     
  44. mariozhou

    mariozhou

    Joined:
    Oct 18, 2019
    Posts:
    23
    Reproduces with 2020.3.5f1
     
  45. Honikou

    Honikou

    Joined:
    Feb 18, 2013
    Posts:
    92
    Same problem on 2020.3.13f1 (LTS)

    I don't understand that such an important problem still exists after so many years.
     
  46. rise9912

    rise9912

    Joined:
    Feb 19, 2018
    Posts:
    10
    Same problem on 2019 LTS version. And even can't find any way to solve this manually. Happens almost every time when any of team members pushes SO changes
     
  47. ichenpipi

    ichenpipi

    Joined:
    Feb 24, 2021
    Posts:
    3
    I have found a working solution (work with 2020.2.5f1):
    1. move the asset and it's meta file out of the project Assets folder
    2. invoke AssetDatabase.Refresh()
    3. Move the asset and its meta file back to their original location
    4. invoke AssetDatabase.Refresh() again

    Here is my code:
    Code (CSharp):
    1. public static async void Reimport(Object asset)
    2. {
    3.     // Asset path
    4.     string assetPath = AssetDatabase.GetAssetPath(asset);
    5.     string filePath = Application.dataPath + assetPath.Substring(6);
    6.     string metaPath = filePath + ".meta";
    7.     FileInfo fileInfo = new FileInfo(filePath);
    8.     string dirPath = fileInfo.DirectoryName!.Replace("\\", "/");
    9.     // Temp dir
    10.     string tempDirPath = Application.dataPath.Replace("/Assets", "");
    11.     string tempFilePath = filePath.Replace(dirPath, tempDirPath);
    12.     string tempMetaPath = tempFilePath + ".meta";
    13.     // Move out of project Assets
    14.     File.Move(filePath, tempFilePath);
    15.     File.Move(metaPath, tempMetaPath);
    16.     AssetDatabase.Refresh();
    17.     // Delay
    18.     await Task.Delay(100);
    19.     // Move back
    20.     File.Move(tempFilePath, filePath);
    21.     File.Move(tempMetaPath, metaPath);
    22.     AssetDatabase.Refresh();
    23.     // Selecte the asset
    24.     Selection.activeObject = AssetDatabase.LoadAssetAtPath<Object>(assetPath);
    25. }