Giter Club home page Giter Club logo

starikcetin / eflatun.scenereference Goto Github PK

View Code? Open in Web Editor NEW
328.0 6.0 22.0 1.96 MB

Unity Scene References for Runtime and Editor. Strongly typed, robust, and reliable. Provides GUID, Path, Build Index, Name, and Address.

Home Page: https://openupm.com/packages/com.eflatun.scenereference/

License: MIT License

C# 69.84% ShaderLab 25.19% HLSL 4.38% Shell 0.58%
reference scene unity unity3d eflatun scenereference plugin unity-package unity-package-manager unity-plugin

eflatun.scenereference's Issues

Entity SubScene Support

Entity scenes work differently from regular scenes.

Opening this issue even though entities is still in preview (though not for long if I heard right). I don't know if they will be modifying this, so perhaps it is too early, but I'll describe the current state.

  • If you load a scene from the build settings, which contains a SubScene, everything works as expected. The SubScene does not need to be in the list directly (in fact, I suspect it is best to make sure it isn't).
  • If you load a SubScene programmatically (using the guid given by this repository's SceneReference for example), the SubScene must be referenced by a scene (can be any) in the build settings, or it will not be able to be loaded.

Personally I've created a scene that contains all my SubScenes and I've added it to the build settings scene list. This works fine.

image
image

FEATURE REQUEST: mapping via static call in-Editor

I'm a big fan of SceneReference but I never liked how it created json files for serialization inside a folder you need to source control. It keeps me from referencing this package inside of other packages, since I would have to communicate users they have to put these extra lines in their source control, and users may find my packages from multiple different sources.

What if you serialized guids inside a json file only once you build the game? And then, in the editor, it uses (something like) this?

public class SceneReference
{
    public SceneAsset sceneAsset;

    public string path => AssetDatabase.GetAssetPath(sceneAsset);
}

Obviously wrapped in #if UNITY_EDITOR where appropriate.

Adding this repo as a submodule is not possible because it's a whole Unity project

Hello there,

the title says it all: We prefer to add utility tools like SceneReference as submodules to our Core-repository. That's only possible if the repo is not a full blown Unity project with assets, meta files and stuff. Is there a reason why this repo is not just the SceneReference code? This would make it much easier for us to add and maintain this repo.

Move RunSceneGUIDToPathMapGenerator MenuItem to Tools tab

Right now MenuItem RunSceneGUIDToPathMapGenerator locates at "Eflatun/Scene Reference".
But Unity projects often have a lot of packages and the toolbar becomes too big.

Would be nice to move the location of the MenuItem under the Tools tab.
For example, "Tools/Eflatun Scene Reference/RunSceneGUIDToPathMapGenerator".

Add CI

Add semantic release CI using GitHub actions.

If you are seeing this, something has gone wrong internally

Hello!

I'm using your excellent SceneReference in a project and I'm getting this error. I have a scene field that is optional and I get this error when I try to access the scene field when no scene is selected.

SceneReferenceInternalException: [Eflatun.SceneReference] If you are seeing this, something has gone wrong internally. Please open an issue on Github (https://github.com/starikcetin/Eflatun.SceneReference/issues) and include the following information: Location: 54783205 Info: AssetGuidHex is invalid. AssetGuidHex: "" Eflatun.SceneReference.SceneReference.get_HasValue () (at ./Library/PackageCache/com.eflatun.scenereference@928ac7f606/Runtime/SceneReference.cs:115)

Regardless of what I try to access on the class, I get the same error. HasValue, IsSafeToUse etc.

Add support for dragging and dropping multiple scene files on lists (& other collections)

The issue:

The package doesn't allow populating a List of SceneReferences with multiple scene files in the inspector (via box selecting multiple files and dragging and dropping in the component's inspector).

Expected behavior:

Dragging and dropping multiple scene files into an list of SceneReferences should allow populating that list with the dropped files.

Steps to reproduce:

  1. Open Unity with any project containing the package
  2. Create an empty object and add a script to it
  3. Inside that script, add a variable of type List<SceneReference>;
  4. Back in the Unity inspector, select multiple scene files and try dragging them into the newly-created List variable; This should not be possible, even though it "would" be expected (as it is a pretty common QoL improvement)

Other

sceneRef_issue.mp4

Fine-grain scene asset modification generation trigger

Hey, another recommendation here!
Currently, the regeneration of the map is defaulted to a setup that occurs whenever I save a scene. This causes it to add info to the console (default setting for the asset is debug logging level) every time I save a scene.
I believe two changes would be great, one is defaulting to warning, not debug.
Another is to listen to scene files being created/deleted instead of each change/save, to generate.
You can add hooks for OnWillDeleteAsset and OnWillCreateAsset.

Sorry if you considered this already. It's just that I work with a very pedant team and the console 'spam' got to them more than the value your plugin generates, which is crazy for me.
Still, amazing work! I hope I'm helping giving suggestions.

Need HasValue at editor time, why is it private?

The title says it all. I need to check if a scene reference has assigned a scene or not, to throw a warning if it's missing. Is there any way to achieve this?
Using State.Unsafe doesn't work because it will mark a scene that's referenced but not in the build settings as Unsafe. I specifically need to know if the designers referenced a scene.

Missing map files cause error during initial editor launch

Steps to reproduce:

  1. Close Unity.
  2. Remove the map files.
  3. Launch project.

Error message:

[Eflatun.SceneReference] Scene GUID to path map file not found!
UnityEngine.Debug:LogError (object)
Eflatun.SceneReference.Logger:Error (string) (at ./Packages/com.eflatun.scenereference/Runtime/Logger.cs:7)
Eflatun.SceneReference.SceneGuidToPathMapProvider:Load () (at ./Packages/com.eflatun.scenereference/Runtime/SceneGuidToPathMapProvider.cs:66)
Eflatun.SceneReference.SceneGuidToPathMapProvider:LoadIfNotAlready () (at ./Packages/com.eflatun.scenereference/Runtime/SceneGuidToPathMapProvider.cs:55)
Eflatun.SceneReference.SceneGuidToPathMapProvider:get_SceneGuidToPathMap () (at ./Packages/com.eflatun.scenereference/Runtime/SceneGuidToPathMapProvider.cs:27)
Eflatun.SceneReference.Editor.MapGeneratorTriggers.SceneAssetPostprocessor:OnPostprocessAllAssets (string[],string[],string[],string[]) (at ./Packages/com.eflatun.scenereference/Editor/MapGeneratorTriggers/SceneAssetPostprocessor.cs:11)
UnityEditor.AssetPostprocessingInternal:PostprocessAllAssets (string[],string[],string[],string[],string[],bool)

The map files are expected to be missing during the initial launch, so we should not print any errors at that point. Though the map generation still turns out fine, I am still marking this issue as a bug since it looks like one.

Suggestion: Add attribute to ignore build check for scenes

Hi, I'd like to suggest an attribute to add to scene reference fields to not draw the build index check for certain scenes only. Maybe even draw such scenes in a different color (blue as default?).

Something like:

[UncheckedSceneReference]
public SceneReference scene;

Some scenes are used only by editor tools and don't need to be in the build index. This would be really useful. Especially because your library is currently the best for handling scene references.

I can code this change if you'd like.

Add Tests

  • Add tests for runtime assembly.
  • Add tests for editor assembly.
  • Add a test that tries to build the project.
  • Configure tests to run on PRs and commits.

There's no way to check if SceneReference is assigned or not

In my code I want to do this:
if (sceneReference != null) { //do something }

However, sceneReference will never be null, and there is no property or method to check if anything has been assigned in the inspector, and HasValue or IsSafeToUse does not work for this use case. Is this intentional or am I missing something?
In my case, I'm using scene reference to set up a map transition script. If the scene reference variable is empty, I want to just teleport the player to a spawn location of the same scene.

Doing any of the following will produce a SceneReferenceInternalException error if the inspector value is empty:
if (sceneReference != null) { //do something }
if (sceneReference.HasValue) { //do something }
if (sceneReference.IsSafeToUse) { //do something }

`[SceneReferenceOptions]` attribute does not work for nested fields

This is an example of when it doesn't work:

public class NestedOptionsTest : MonoBehaviour
{
    [SerializeField] private Container container;
}

[Serializable]
public class Container
{
    [SceneReferenceOptions(UtilityLine = UtilityLineBehaviour.Disabled, Coloring = ColoringBehaviour.Enabled)] 
    [SerializeField] private SceneReference sceneReferenceField;
}

Color Based On Scene-In-Build State Exceptions

Minor feature request

At the moment 'Color Based On Scene-In-Build State' is a overall setting that highlights whether a scene is in the build or not.

I have a Scene Reference that is not in the build as it's for editor purposes only, but it highlights red in the Inspector. It would be great to be able to add this scene to an 'exceptions' list. Via preferences and using the Scene Reference Toolbox dropdown menu.

Feature Request: Add "Open Build Settings..." opion

The Problem

I think I'd rather go to Build Settings and add the scene there manually if it's missing, so I can control it's exact placement, rather than just press the Add to Build button and leave it at that.

Potential Solutions

  1. The dialog that opens when you press the Add to Build button could contain an Open Build Settings... option. That would be more useful for me than the Add to Build as Disabled option it currently has.
  2. A context menu item for opening Build Settings (EditorApplication.ExecuteMenuItem("File/Build Settings...")). The good thing about this would be that it could be used even after the Add to Build button has already gone away. The downside is that it would be easy to miss this feature, as it's completely hidden.

Addressable Scene Support

if scene is marked as addressable, the scenemap json generator should refresh, and save to the json the addressable key. This will allow in runtime to then run Addressables.LoadResourceLocationsAsync(MySceneReference.addressableKey), which will find you the scene in the addressable catalog and from there you can load the asset through the addressables system.

GitIgnored scenes being added to SceneGuidToPathMap json

(1) Add one of your scenes to .gitignore
(2) run SceneGuitToPathMap. the .gitignored scene will be partof the json.
(3) howeber, other users of the repo wont have that scene in their proj (since gitignored) but it wil be listed in the map.

there could be potential issues where users create a new asset, and it gets randomly assigned the same guid that according to the scene map is pointing to a scene, but accoriding to unity its pointing to a completely unrelated asset.

Investigate compatibility issues with `BinaryFormatter`

Discussed in #26

Originally posted by Rava4U November 28, 2022
Hi!
In a game I'm trying to develop (as a total beginner, by the way, so please be patient with me:-) ) I'm using the JohannesMP's version of this Scene Reference tool, which I'm finding extremely helpful. However, I came across a small personal issue: it looks like SceneReference is not serializable, or at least trying to create a save file containing Scene Reference through the binary formatter causes a Serialization Exception error.
My questions are:

  • is JohannesMP's SceneReference serializable? I couldn't find the answer by myself and, if I understood correctly, that version of the project is no longer supported, that's why I came here!
  • is THIS Scene Reference tool serializable, alternatively? It would be a great help if it was (otherwise, I have a suitable, even if less practical, plan B for what I need to do).
    Any help is greatly welcome!

Andrea

PS: I'm also new to GitHub, so forgive me if I'm asking things the wrong way or in the wrong place

GenerationTriggers not rendering in Project Settings inspector (2022.3)

Something about the SceneDataMapsGeneratorTriggers enum isn't sitting well with the Editor settings window: while the GenerationTriggers user setting field is set to be rendered (i.e. its attribute is not commented out), an IndexOutOfRangeException and InvalidCastException occur, and the entire settings menu fails to render. This occurs both on Windows and Mac, in 2022.3.

image

Visually improve inline utility

Currently, when the inline utility line shows up for consecutive fields, it is not clear which field the utility line belongs to, especially if they are colored the same way. We need to improve the visual representation to make it visually clear which utility belongs to which field.

demo scenes use TMP but its not part of package dependencies

Some demo scenes use TextMeshPro - Text (UI) component. These work fine if TextMeshPro package is already installed in your project. however, if missing the package, those components will be missing.

if SceneReference Package is added TMP as part of dependencies, it could be weird to be forced to install TMP for a package that doesnt deal with UI.
But if demo scenes are modified to use regular text component as it should be sufficient?

Documentation/API improvement: SceneReference is serialized so we must check AssetGuidHex not empty, else need IsValid method

I wanted to check if SceneReference was null before using it, but due to serialization, Unity creates a default instance with invalid fields (sceneAsset is null, strings are empty, other properties cause exception on access).

So, basically, my null check if (mySceneReference != null) is always verified, and my code tries to use it even when not set.

Trying to access BuildIndex then causes an obscure error:

KeyNotFoundException: The given key '' was not present in the dictionary.
System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <7560840559c84ffbb83a08c4696f01f7>:0)
Eflatun.SceneReference.SceneReference.get_Path () (at Library/PackageCache/[email protected]/Runtime/SceneReference.cs:26)
Eflatun.SceneReference.SceneReference.get_BuildIndex () (at Library/PackageCache/[email protected]/Runtime/SceneReference.cs:31)

There's not much to do about it if we want to serialize the whole class, but at least the README documentation should indicate in usage that before using the field, it may be good to check for if (!string.IsNullOrEmpty(mySceneReference.AssetGuidHex) or the likes.

I also tried to check mySceneReference.sceneAsset != null, but the field is internal so I could not access it. I suppose we could add a bool IsValid() method that checks sceneAsset to avoid the more complicated AssetGuidHex check.

Unsupported type SceneReference

I use Unity 2022.3.6f1

I assign a value to SceneName in a script that contains OnValidate()

[SerializeField] private SceneReference nextScene;
public string SceneName = "";

#if UNITY_EDITOR
void OnValidate()
{
    SetMissionValue();
}
#endif

void Awake()
{
    SetMissionValue();
}

void SetMissionValue()
{
    if (nextScene.State == SceneReferenceState.Regular)
        SceneName = nextScene.Name;
}

The editor throws an error:

Unsupported type SceneReference
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

Continuous NullReferenceException when Addressables Settings not initialised

Initially thought it was an incompatability with Odin Inspector.

Uninstalling Addressables package worked to stop the continuous logging.

But found out it was because I hadn't initialised Addressable Settings yet - ie the package was installed but I haven't got round to using it yet in the Project.

Maybe a check needed somewhere.

`[Exception] NullReferenceException: Object reference not set to an instance of an object
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
Rethrow as OdinPropertyException: This error occurred while being drawn by Odin.
Current IMGUI event: repaint
Odin Property Path: worldScene
Odin Drawer Chain:

PropertyContextMenuDrawer
ReferenceDrawer
FixUnityNullDrawer
NullableReferenceDrawer
UnityPropertyDrawer<SceneReferencePropertyDrawer, SceneReference>
CompositeDrawer.
SceneReferencePropertyDrawer.Init() at Library/PackageCache/com.eflatun.scenereference@c94f1c9902/Editor/SceneReferencePropertyDrawer.cs:84

SceneReferencePropertyDrawer.OnGUI() at Library/PackageCache/com.eflatun.scenereference@c94f1c9902/Editor/SceneReferencePropertyDrawer.cs:129

PropertyDrawer.OnGUISafe() at /Users/bokken/build/output/unity/unity/Editor/Mono/ScriptAttributeGUI/PropertyDrawer.cs:23

PropertyHandler.OnGUI() at /Users/bokken/build/output/unity/unity/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:170

PropertyHandler.OnGUI() at /Users/bokken/build/output/unity/unity/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:131

RuntimeMethodInfo.Invoke() at :0

UnityPropertyHandlerUtility.PropertyHandlerOnGUI() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Value Drawers/UnityPropertyHandlerUtility.cs:216

Sirenix.OdinInspector.Editor.UnityPropertyDrawer`2[TDrawer,TDrawnType].DrawPropertyLayout() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Value Drawers/UnityPropertyDrawer.cs:127

OdinDrawer.CallNextDrawer() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155

Sirenix.OdinInspector.Editor.Drawers.NullableReferenceDrawer`1[T].DrawPropertyLayout() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/NullableReferenceDrawer.cs:113

OdinDrawer.CallNextDrawer() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155

Sirenix.OdinInspector.Editor.Drawers.FixUnityNullDrawer`1[T].DrawPropertyLayout() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/FixUnityNullDrawer.cs:87

OdinDrawer.CallNextDrawer() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155

Sirenix.OdinInspector.Editor.Drawers.ReferenceDrawer`1[T].DrawPropertyLayout() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/ReferenceDrawer.cs:118

OdinDrawer.CallNextDrawer() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155

Sirenix.OdinInspector.Editor.Drawers.PropertyContextMenuDrawer`1[T].DrawPropertyLayout() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/PropertyContextMenuDrawer.cs:659

OdinDrawer.DrawProperty() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:109

InspectorProperty.Draw() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:849

Debug.LogException()

InspectorProperty.Draw() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:926

InspectorProperty.Draw() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:737

UnityObjectRootDrawer`1.DrawPropertyLayout() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Value Drawers/UnityObjectRootDrawer.cs:60

OdinDrawer.CallNextDrawer() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:155

FixBrokenUnityObjectWrapperDrawer`1.DrawPropertyLayout() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Attribute Drawers/FixBrokenUnityObjectWrapperDrawer.cs:41

OdinDrawer.DrawProperty() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinDrawer.cs:109

InspectorProperty.Draw() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/InspectorProperty.cs:849

PropertyTree.DrawProperties() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/PropertyTree.cs:552

PropertyTree.Draw() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/PropertyTree.cs:444

OdinEditor.DrawTree() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:97

OdinEditor.DrawOdinInspector() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:254

OdinEditor.OnInspectorGUI() at C:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:79

GUIUtility.ProcessEvent() at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:189
`

auto trigger script reload after entering play mode

Thanks for your hard work! My problem is, the package would trigger script reload when entering play mode, which breaks my hot reload workflow. Remove the package would fix the problem, do you have any idea about it?

Add support for SceneReference type properties in Unity Events in inspector

While this is minor and can be easily worked around, I did notice that when you create a method like this one

public void LoadSceneAdditive(SceneReference sceneReference)
{
      if (sceneReference.State == SceneReferenceState.Unsafe)
      {
            Debug.LogError($"scene reference is unsafe!: {sceneReference.UnsafeReason}");
            return;
      }
           
      SceneManager.LoadSceneAsync(sceneReference.BuildIndex, LoadSceneMode.Additive);
}

then in the inspector for something like a button, it doesn't show up when registering it for a unity event

image

again, this is a very minor issue as it's straightforward to work around with a separate script that can sit on each button to hold the ScreenReference but it would be a nice QOL thing to have added

NotInMaps false positive

We started using the plugin a few days ago, but shortly after implementation, we encountered erratic failures in our unit test suite. One test, responsible for validating scene references across our prefabs, began exhibiting inconsistent behavior.

Our test looks like this:

            if (scene.State == SceneReferenceState.Unsafe)
            {
                Debug.LogError($"There's a problem with the scene settings. Reason: '{scene.UnsafeReason}'");
            }

So while all works well in editor, turns out that the unit tests running on a remote self-hosted linux machine fail sometimes.
Investigating a bit, it seems that the SceneDataMap was sometimes not generated by the time the test was trying to run, thus failing with "NotInMaps" message.

We added this to make sure the maps were generated before running any tests, and it seems to be working fine now.

        [SetUp]
        public void SetUpTests()
        {
            SceneDataMapsGenerator.Run(false);
        }

However, we're left wondering if this behavior is expected or if others have encountered similar challenges when running tests through GitHub Actions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.