Search Unity

Read-Only Scenes in Packages

Discussion in 'Package Manager' started by sbinter_levelex, May 15, 2020.

  1. sbinter_levelex

    sbinter_levelex

    Joined:
    Jul 5, 2018
    Posts:
    9
    So my company has stumbled into a bit of a problem in our deployment of scoped repositories - Scenes in our packages.

    Previously these packages were distributed via a somewhat tenuous system of remapping perforce views to distribute package contents at specific revisions - and this worked alright for scenes since technically they were write-able even though the mapping prevented submission via 1-way imports.

    We've switched to a private scoped repository and are now using the UPM, but people can't test read-only scenes that we distribute in packages and use as portions of a composite of multiple scenes. We're not trying to save or alter data in these scenes, simply load and test them as portions of multi-scene levels.

    We can only load them through runtime - actually playing the game. But you can never pull up and play a level in isolation now, since you can't actually load the scenes to play them in editor.

    I want to point out that a samples workflow doesn't really fit the bill here as this isn't a sample in and of itself, and should retain its read-only quality. (reference material https://forum.unity.com/threads/can...ckages-cant-load-scenes-from-packages.590764/ and https://forum.unity.com/threads/samples-in-packages-manual-setup.623080/)

    Has anyone found a workaround for this? Are there any plans to allow the loading of read-only scenes? I'm curious why the decision was made to block this behavior, instead of preventing actually saving a changed state.
     
  2. ShawnFeatherly

    ShawnFeatherly

    Joined:
    Feb 22, 2013
    Posts:
    57
  3. sbinter_levelex

    sbinter_levelex

    Joined:
    Jul 5, 2018
    Posts:
    9
    That's actually a much better solution than the stopgap one we'd devised which included a hybrid package/import system. We'll probably switch to that in the short term for the projects and packages that can utilize it.

    We're still hoping that there is or could be a way to simply play read-only scenes, as the read-only flag is useful for homogeneity between projects and the prevention of further modification to scenes that are meant to be static.
     
  4. ShawnFeatherly

    ShawnFeatherly

    Joined:
    Feb 22, 2013
    Posts:
    57
    I just tried using Client.Embed called from inside of a scopedRegistry package in Unity2019.3.12. It did nothing. The package stayed read-only. I hit a breakpoint to make sure the function was called with the correct package name string.

    This function does throw an error correctly when it's called in a package that's already local/embedded.
     
  5. UnityMaru

    UnityMaru

    Community Engagement Manager PSM

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

    I've heard back from the Package Manager team that this is a known limitation and that it's something we could have a workaround for, but we can't provide any form of ETA on this at this time.
     
  6. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    We have similar issue
    https://forum.unity.com/threads/it-...n-a-scene-in-a-read-only-package-why.1148036/

    Are there any news about the workaround?
    Does bug report is relevant in this case? Should we report with a basic project?
     
  7. UnityMaru

    UnityMaru

    Community Engagement Manager PSM

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    Hey there,

    The stance remains as I pointed out last year - it's something the team want to look at but there's more pressing things that the team want to focus/implement first before they can dig into this.

    Other than making the package non-immutable (local or embedded), there is not else you will be able to do.
     
    De-Panther likes this.
  8. OxDEADFACE

    OxDEADFACE

    Joined:
    Jul 6, 2017
    Posts:
    33
    The simplest workaround I can come up with is:
    • copy the `*.unity` Scene asset from the read-only package location to anywhere you like in the `Assets/**` space.
    • (drag-and-drop within the Project window works just fine)
    • voila. the Scene can be opened, viewed, etcetera from within the Asset space, and reference assets and scripts in the Package space just fine.
    For me, this is a perfectly fine solution, because the Scenes in question are just some samples for Spine. I can't currently think of a case where this easy fix would be inadequate, but best of luck either way!

    ♠ LP
     
    joelrunji and gxchris like this.
  9. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    In our case, we do want it to be un-editable. So a copy of the scene in the assets folder is not a complete solution
     
  10. Johste

    Johste

    Joined:
    Jul 12, 2014
    Posts:
    18
    We made this script as a workaround. Its a bit hackish for some, but works fine.

    Right click the SceneAsset you want and click "Play".

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditor.SceneManagement;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class PlayReadOnlySceneMenuOptions : Editor
    7. {
    8.     [MenuItem("CONTEXT/SceneAsset/Play")]
    9.     private static void Play(MenuCommand menuCommand) => Play(menuCommand.context as SceneAsset);
    10.  
    11.     [MenuItem("Assets/Play")]
    12.     private static void Play() => Play(Selection.activeObject as SceneAsset);
    13.  
    14.     [MenuItem("Assets/Play", true)]
    15.     private static bool SceneAssetValidation() {
    16.         return Selection.activeObject is SceneAsset && Selection.objects.Length == 1;
    17.     }
    18.  
    19.     private static void Play(SceneAsset scene)
    20.     {
    21.         Debug.Log($"{nameof(Play)} {scene.name}");
    22.         if (Application.isPlaying)
    23.         {
    24.             SceneManager.LoadScene(scene.name);
    25.         }
    26.         else
    27.         {
    28.             if(EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
    29.             {
    30.                 EditorPrefs.SetString(nameof(PlayReadOnlySceneMenuOptions), scene.name); //For some reason setting a variable was not working. Using EditorPrefs as a workaround.
    31.                 EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
    32.                 EditorApplication.isPlaying = true;
    33.             }
    34.         }
    35.     }
    36.    
    37.     [RuntimeInitializeOnLoadMethod]
    38.     private static void OnRuntimeMethodLoad()
    39.     {
    40.         string sceneName = EditorPrefs.GetString(nameof(PlayReadOnlySceneMenuOptions));
    41.         if (!string.IsNullOrWhiteSpace(sceneName))
    42.         {
    43.             EditorPrefs.DeleteKey(nameof(PlayReadOnlySceneMenuOptions));
    44.             SceneManager.LoadScene(sceneName);
    45.         }
    46.     }
    47. }
    48.  
     
    KyryloKuzyk likes this.
  11. gxchris

    gxchris

    Joined:
    Nov 28, 2020
    Posts:
    3
    Smart! solved my issue!