Search Unity

  1. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

Check if asset inside package is readonly

Discussion in 'Package Manager' started by Araj, May 29, 2020.

  1. Araj

    Araj

    Joined:
    Jan 3, 2013
    Posts:
    27
    Hi!

    I am making a tool to check all the assets in the project and validate a few things, the problem that I have is that when I try to open a scene that is inside a package I get an error telling me that as the package is read only, i can't open that scene.

    Is there a way to check if a package is readonly by code?
     
  2. UnityMaru

    UnityMaru

    Community Engagement Manager Unity Technologies

    Joined:
    Mar 16, 2016
    Posts:
    1,126
    Hi there,

    There is no direct way to verify this, but you can follow these steps to avoid opening the scene if it's going to fail due to this read-only state:

    1) Before opening the scene, call `UnityEditor.PackageManager.PackageInfo.FindForAssetPath(<path-to-scene-asset>);`
    2) If the above is "null", the scene is not in a package and can be opened.
    3) Otherwise, check the `source` property of the returned PackageInfo. If it's `PackageSource.Embedded` or `PackageSource.Local`, it can safely be opened. Otherwise, it's in an immutable package and cannot be opened.
     
unityunity