Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update exporting_pcks.rst #8486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Heremeus
Copy link

Updating C# assembly loading instructions according to godotengine/godot#75352 (comment). Simply loading the assembly is no longer enough with godot 4 and @granitrocky identified how to load the dlls correctly.

Wasn't sure how to properly format the code inside the note block, so please suggest improvements, if necessary.

Updating C# assembly loading instructions according to godotengine/godot#75352
Copy link
Member

@raulsntos raulsntos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LookupScriptsInAssembly method (as most everything else in the Godot.Bridge namespace) is not meant to be used by users, if this API is exposed it's only because it's used by our source generators but otherwise it'd be internal API.

So I don't feel comfortable telling users to use this API. At least not without the proper explanation of what's happening.

Also, the plan was to make the type ScriptManagerBridge internal and replace the LookupScriptsInAssembly method with source generators (ScriptRegistrarGenerator), so it'd be better if users didn't start relying on this API since we'll likely break compatibility here.

@@ -132,7 +132,7 @@ The PCK file contains a “mod_scene.tscn” test scene in its root.
.. note::
For a C# project, you need to build the DLL and place it in the project directory first.
Then, before loading the resource pack, you need to load its DLL as follows:
``Assembly.LoadFile("mod.dll")``
``var context = AssemblyLoadContext.GetLoadContext(typeof(Godot.Bridge.ScriptManagerBridge).Assembly); var assembly = context.LoadFromAssemblyPath("mod.dll"); Godot.Bridge.ScriptManagerBridge.LookupScriptsInAssembly(assembly);``
Copy link
Member

@raulsntos raulsntos Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work for multi-line code:

Suggested change
``var context = AssemblyLoadContext.GetLoadContext(typeof(Godot.Bridge.ScriptManagerBridge).Assembly); var assembly = context.LoadFromAssemblyPath("mod.dll"); Godot.Bridge.ScriptManagerBridge.LookupScriptsInAssembly(assembly);``
.. code-block:: csharp
var context = Assembly.LoadContext.GetLoadContext(typeof(Godot.Bridge.ScriptManagerBridge).Assembly);
var assembly = context.LoadFromAssemblyPath("mod.dll");
Godot.Bridge.ScriptManagerBridge.LookupScriptsInAssembly(assembly);

@raulsntos raulsntos added topic:dotnet area:manual Issues and PRs related to the Manual/Tutorials section of the documentation labels Nov 16, 2023
@granitrocky
Copy link

granitrocky commented Nov 16, 2023

@raulsntos That was a genuine concern of mine since there is a comment in the ScriptManagerBridge saying that the LookupScriptsInAssembly method is planned to go private. An alternative could be setting up an AssemblyLoad callback that calls it internally. Although if it's planned to be replaced with generators, we will need to consider mod support.

Somehow the Scripts in the imported dll need to be associated with the dictionary that tracks them. Maybe in that callback I mentioned?

@Heremeus
Copy link
Author

The LookupScriptsInAssembly method (as most everything else in the Godot.Bridge namespace) is not meant to be used by users, if this API is exposed it's only because it's used by our source generators but otherwise it'd be internal API.

So I don't feel comfortable telling users to use this API. At least not without the proper explanation of what's happening.

Also, the plan was to make the type ScriptManagerBridge internal and replace the LookupScriptsInAssembly method with source generators (ScriptRegistrarGenerator), so it'd be better if users didn't start relying on this API since we'll likely break compatibility here.

That's totally fair, thanks for the insight! Feel free to close this issue and notify other users on the original issue. If I understood it correctly, the assembly workflow will be reworked in a future version which should fix the issue?

@Carsillas
Copy link

The LookupScriptsInAssembly method (as most everything else in the Godot.Bridge namespace) is not meant to be used by users, if this API is exposed it's only because it's used by our source generators but otherwise it'd be internal API.

So I don't feel comfortable telling users to use this API. At least not without the proper explanation of what's happening.

Also, the plan was to make the type ScriptManagerBridge internal and replace the LookupScriptsInAssembly method with source generators (ScriptRegistrarGenerator), so it'd be better if users didn't start relying on this API since we'll likely break compatibility here.

I hope it is prioritized that the original issue is resolved prior to making this breaking change, I intend on using this in the meantime and would like to not be completely blocked from keeping my engine up to date.

@haltingstate
Copy link

What is the method now, to load scripts that are in runtime loadable assemblies, or to load scripts that are outside of the Godot project folder?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:manual Issues and PRs related to the Manual/Tutorials section of the documentation topic:dotnet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants