Title: How to trigger NGO CodeGen via custom buildpipeline? · Issue #2747 · Unity-Technologies/com.unity.netcode.gameobjects · GitHub
Open Graph Title: How to trigger NGO CodeGen via custom buildpipeline? · Issue #2747 · Unity-Technologies/com.unity.netcode.gameobjects
X Title: How to trigger NGO CodeGen via custom buildpipeline? · Issue #2747 · Unity-Technologies/com.unity.netcode.gameobjects
Description: This is a long shot and I'm assuming/guessing things based on what I have researched. I also know I'm pushing the limits here - but hey somebody have to do it :) Background The background for this is that my game supports mods and I'm cu...
Open Graph Description: This is a long shot and I'm assuming/guessing things based on what I have researched. I also know I'm pushing the limits here - but hey somebody have to do it :) Background The background for this ...
X Description: This is a long shot and I'm assuming/guessing things based on what I have researched. I also know I'm pushing the limits here - but hey somebody have to do it :) Background The background f...
Opengraph URL: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/2747
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"How to trigger NGO CodeGen via custom buildpipeline?","articleBody":"This is a long shot and I'm assuming/guessing things based on what I have researched.\r\nI also know I'm pushing the limits here - but hey somebody have to do it :)\r\n\r\n# Background\r\nThe background for this is that my game supports mods and I'm currently working on adding multiplayer to my game using NGO.\r\n\r\nSo far things are going pretty good - but there is one major issue I still haven't figured out and it's a really big deal as mod creators will be very limited if I can't get this to work.\r\n\r\nI'm using UMod to help support mods in my game (https://assetstore.unity.com/packages/tools/integration/umod-2-0-58293).\r\nAs far as I understand, it adds feature on top and around Asset Bundles.\r\n\r\nThe way UMod work is pretty nice.\r\n\r\nAs the developer of the game (me) I setup various things, like what scripts should be included in the \"Mod Tools\" and other settings. I then build the \"Mod Tools\" for my game from inside Unity. This result in a .unitypackage file.\r\n\r\nAs the mod creators (people from the community) you then open up a fresh Unity and import this .unitypackage file (Mod Tools) and get some Unity windows to create a \"mod\" and can then build a mod - which can include custom scripts.\r\n\r\nThe mod creator then \"build mod\" from a custom Unity menu made by UMod, which generates a .mod file that the game can then pick up. At least simply put - the important part here is the UMod builds the mod here. Remember that.\r\n\r\n# The problem\r\nSo, I have discovered that ClientRPCs, ServerRPCs and NetworkVariables are NOT working if a modder is using it in his custom scripts.\r\n\r\nI have done some research that indicates (and here comes the guessing part) that NGO is doing some CodeGen at \"game build time\" - I guess here: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/develop/com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs\r\n\r\nI'm guessing that it doesn't work, because this CodeGen is not happening on the custom scripts in the mod when it's build by UMod. \r\n\r\n```\r\nUMod supports custom BuildProcessors to run custom code when building the mods like this:\r\nusing System.Collections.Generic;\r\nusing UMod.BuildEngine;\r\nusing UMod.BuildPipeline;\r\nusing UMod.BuildPipeline.Build;\r\nusing UMod.Shared.Resources;\r\nusing UnityEngine;\r\n\r\n// Add a build processor for script assets since we are only interested in scripts that will be compiled by uMod.\r\n// High priority means that it will run after script compilation so build assemblies collection will already be filled out with compiled assemblies.\r\n[UModBuildProcessor(\".cs\", 1000, true)]\r\npublic class PatchAssembliesExample : BuildEngineProcessor\r\n{\r\n // Methods\r\n // Called by the build engine just after compilation if the mod includes any script content, passing all script assets as a parameter (Not interested in those).\r\n public override void ProcessAssetBatch(BuildContext context, IEnumerable\u003cBuildPipelineAsset> assets)\r\n {\r\n // get assemblies\r\n ModAssemblyEntry[] entries = context.BuildAssemblies.Assemblies;\r\n\r\n // Patch all\r\n foreach(ModAssemblyEntry entry in entries)\r\n {\r\n PatchAssembly(context, entry);\r\n }\r\n }\r\n\r\n private void PatchAssembly(BuildContext context, ModAssemblyEntry entry)\r\n {\r\n // Name info\r\n string asmName = entry.AssemblyName;\r\n\r\n // Get assembly image - loadable by 'Assembly.Load'\r\n byte[] asmImage = entry.AssemblyImage;\r\n\r\n\r\n // TODO - Run custom patcher code\r\n\r\n\r\n // Get the patched result\r\n byte[] asmImagePatched = ...;\r\n\r\n // Check for patched\r\n if (asmImagePatched != null)\r\n {\r\n // Remove original assembly\r\n context.BuildAssemblies.RemoveFromBuild(entry);\r\n\r\n // Register new assembly\r\n if (context.BuildAssemblies.RegisterAssemblyForBuild(asmImagePatched, true) == false)\r\n Debug.LogWarning(\"Failed to register patches assembly for build! : \" + asmName);\r\n }\r\n }\r\n}\r\n```\r\n\r\nSo, here comes the million dollar question that will make the sky the limits for modders of my game - how can I trigger this CodeGen for the scripts in the mod?\r\n\r\nNote that NGO is installed as a dependency to the Mod Tools, so NGO is installed in the mod creators Unity project.\r\n\r\n\r\n\r\n\r\n","author":{"url":"https://github.com/Laumania","@type":"Person","name":"Laumania"},"datePublished":"2023-10-20T16:33:44Z","url":"https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/2747"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:bbdb3fa8-cf36-abef-02be-884ed2036637 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E18C:27FBAD:2D1A64:3D951F:6B006A3D |
| html-safe-nonce | 6716d42426220a2f212067a1bf5fba2125d57433986f4bfaecc952e426f4e3c2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMThDOjI3RkJBRDoyRDFBNjQ6M0Q5NTFGOjZCMDA2QTNEIiwidmlzaXRvcl9pZCI6IjgwNDkwODM4OTUzNTYwNzM1NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2ba31e2004ae188187ca37c767f592d2d56c49bcc759d258b31f578096d27c6c |
| hovercard-subject-tag | issue:1954661047 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/Unity-Technologies/com.unity.netcode.gameobjects/2747/issue_layout |
| twitter:image | https://opengraph.githubassets.com/301ac0a9c3d887b17dfbb5f890a92cfc142365c3c55bb08a7a4f79128627c86d/Unity-Technologies/com.unity.netcode.gameobjects/issues/2747 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/301ac0a9c3d887b17dfbb5f890a92cfc142365c3c55bb08a7a4f79128627c86d/Unity-Technologies/com.unity.netcode.gameobjects/issues/2747 |
| og:image:alt | This is a long shot and I'm assuming/guessing things based on what I have researched. I also know I'm pushing the limits here - but hey somebody have to do it :) Background The background for this ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Laumania |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6527e91c60c0b29d16606ff32ac5df8ecdc37a2a62205ea057a14d7762c870fa |
| turbo-cache-control | no-preview |
| go-import | github.com/Unity-Technologies/com.unity.netcode.gameobjects git https://github.com/Unity-Technologies/com.unity.netcode.gameobjects.git |
| octolytics-dimension-user_id | 426196 |
| octolytics-dimension-user_login | Unity-Technologies |
| octolytics-dimension-repository_id | 116385203 |
| octolytics-dimension-repository_nwo | Unity-Technologies/com.unity.netcode.gameobjects |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 116385203 |
| octolytics-dimension-repository_network_root_nwo | Unity-Technologies/com.unity.netcode.gameobjects |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 46f1cd2ae3cd8ae1a81019b5d619742e76f13bbd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width