{"id":13525249,"url":"https://github.com/31/GodotOnReady","last_synced_at":"2025-04-01T04:31:36.803Z","repository":{"id":37641108,"uuid":"328326133","full_name":"31/GodotOnReady","owner":"31","description":"A C# Source Generator that adds convenient onready-like features to your C# scripts in Godot Mono (3.x) without any reflection.","archived":false,"fork":false,"pushed_at":"2023-03-31T02:39:35.000Z","size":170,"stargazers_count":121,"open_issues_count":4,"forks_count":13,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-08-02T06:17:35.977Z","etag":null,"topics":["csharp-sourcegenerator","godot-mono"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/GodotOnReady","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/31.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-01-10T07:19:27.000Z","updated_at":"2024-07-31T05:28:59.000Z","dependencies_parsed_at":"2024-04-18T21:50:01.295Z","dependency_job_id":null,"html_url":"https://github.com/31/GodotOnReady","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/31%2FGodotOnReady","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/31%2FGodotOnReady/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/31%2FGodotOnReady/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/31%2FGodotOnReady/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/31","download_url":"https://codeload.github.com/31/GodotOnReady/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222698222,"owners_count":17024879,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp-sourcegenerator","godot-mono"],"created_at":"2024-08-01T06:01:17.138Z","updated_at":"2024-11-02T09:30:55.881Z","avatar_url":"https://github.com/31.png","language":"C#","funding_links":[],"categories":["Plugins and scripts"],"sub_categories":["3D"],"readme":"# GodotOnReady\n\n**GodotOnReady** is a [C# Source Generator] for Godot 3.x that adds convenient `onready`-like\nfeatures to your C# scripts in Godot Mono without any reflection.\n\n* [`[OnReadyGet]`](#onreadyget) - Load a `Node` or `Resource` subclass into a\n  field or property. Automatically exports a property so you can use the Godot\n  editor to configure the path it loads.\n* [`[OnReady]`](#OnReady) - Execute any 0-argument method during `_Ready`.\n\nBonus feature:\n\n* [`[GenerateDataSelectorEnum]`](docs/GenerateDataSelectorEnum.md) - Generate an enum\n  where each value is strongly associated with custom data.\n\n## Prerequisites\n\n* Godot 3.x, Mono version  \n  \u003chttps://godotengine.org/download\u003e  \n  (4.0+ not supported due to C# source generator conflicts: [GodotOnReady#49](https://github.com/31/GodotOnReady/issues/49))\n\n* .NET SDK 6.0 or greater  \n  \u003chttps://dotnet.microsoft.com/download\u003e\n\n* Set Godot to use the `dotnet CLI` Build Tool  \n  \u003cdetails\u003e\u003csummary\u003eScreenshot showing this editor setting (click me!)\u003c/summary\u003e\n\n  ![](docs/img/EditorSettings-BuildTool-cli.png)\n\n  \u003c/details\u003e\n\n## Project setup\n\nJust add the [`GodotOnReady`](https://www.nuget.org/packages/GodotOnReady)\nNuGet package to your project!\n\nYour Godot project's `.csproj` file should look like this when you're done:\n\n```xml\n\u003cProject Sdk=\"Godot.NET.Sdk/3.3.0\"\u003e\n  \u003cPropertyGroup\u003e\n    \u003cTargetFramework\u003enet472\u003c/TargetFramework\u003e\n  \u003c/PropertyGroup\u003e\n  \u003cItemGroup\u003e\n    \u003cPackageReference Include=\"GodotOnReady\" Version=\"1.2.4\" /\u003e\n  \u003c/ItemGroup\u003e\n\u003c/Project\u003e\n```\n\n`GodotOnReady` includes two subpackages: a C# class library with a few attributes, and a source generator that detects when you use those attributes and generates code behind the scenes.\n\nAfter clicking Build one time to set up the package, you may need to restart your IDE to let the generator load and provide autocomplete/intellisense information.\n\n\u003e For advanced alternatives like building from source or avoiding a reference to `GodotOnReady.Attributes`, see [/docs/advanced-setup.md](/docs/advanced-setup.md).\n\n## Usage\n\n### `[OnReadyGet]`\n\nInstead of writing this repetitive code:\n\n```cs\npublic class MyControl : Control\n{\n  [Export] public NodePath ButtonPath { get; set; }\n  private Button _button;\n\n  public override void _Ready()\n  {\n    _button = GetNode\u003cButton\u003e(ButtonPath);\n  }\n}\n```\n\nWrite this code instead to do the same thing:\n\n```cs\npublic partial class MyControl : Control\n{\n  [OnReadyGet] private Button _button;\n}\n```\n\nThe source generator figures out that the exported property should be called\n`ButtonPath` by taking `_button`, trimming the leading `_` character, and\ncapitalizing the first letter.\n\nThe generated `_Ready()` method calls `base._Ready()` to support inheritance,\nand includes some extra code to throw a more useful error message when the\n`GetNode` fails.\n\nThe `[OnReadyGet]` source generator works for fields and properties. It also\nworks for `Resource` subclasses like `PackedScene` and `Texture`. You can also\nuse an `interface`, in which case GodotOnReady assumes the interface is\nimplemented by a node.\n\n### `[OnReadyGet(...)]`\n\nIf you pass a string to the attribute, it's used as the node path to get. The\n`[Export]` `ButtonPath` property isn't generated. This is useful if you know the\nnode will always be at a certain path, and avoids cluttering the Godot editor\nwith exported properties you'll never use:\n\n```cs\n[OnReadyGet(\"My/Button/Somewhere\")] private Button _button;\n```\n\nIf you know the node will usually be at one path, but someone may need to tweak\nit in the Godot editor to point somewhere else, set `Export = true`. This sets\nthe string as the default path, and *also* exports `ButtonPath` for tweaking in\na scene:\n\n```cs\n[OnReadyGet(\"My/Button/Somewhere\", Export = true)] private Button _button;\n```\n\nTo get a node if it exists and ignore issues, pass `OrNull = true`. This means\nGodotOnReady does nothing if the the path is `null`, empty, invalid, or points\nat the wrong type of node. Normally, it throws an exception in these cases.\n\nIf you use `OrNull = true`, the `_button` member may be null, so be sure to\ncheck before using it!\n\n```cs\n[OnReadyGet(\"My/Button/Maybe\", OrNull = true)] private Button _button;\n```\n\nIf your property is a `Resource` rather than a `Node`, pass a resource path\ninstead of a node path:\n\n```cs\n[OnReadyGet(\"res://icon.png\")] private Texture _tex;\n```\n\nTo get a property of a node instead of getting the node itself, specify\n`Property = \"...\"`. GodotOnReady will cast the result for you, so this is\nparticularly useful for properties that aren't exposed in the statically-typed\nGodot C# API.\n\nFor example, you can get an animation tree playback object without calling\n`.Get(\"...\")` and casting the result yourself:\n\n```cs\n[OnReadyGet(\"AnimationTree\", Property = \"parameters/playback\")]\nprivate AnimationNodeStateMachinePlayback _playback;\n```\n\n---\n\n### `[OnReady]`\n\nUsing `OnReadyGet` causes GodotOnReady to generate a `public override void\n_Ready()` method. This means you can't define `_Ready()` yourself. To run your\nown code during `_Ready`, mark any number of zero-argument methods with\n`[OnReady]`:\n\n```cs\n[OnReadyGet(OrNull = true)] private Button _button;\n[OnReady] private void ConnectButtonOnReady()\n{\n  _button?.Connect(\"pressed\", this, nameof(ButtonPressed));\n}\n```\n\nThe generated `_Ready()` method will then be:\n\n```cs\npublic override void _Ready()\n{\n  base._Ready();\n  if (ButtonPath != null) _button = GetNodeOrNull\u003cglobal::Godot.Button\u003e(ButtonPath);\n  ConnectButtonOnReady();\n}\n```\n\n### `[OnReady(...)]`\n\n`OnReady` accepts one optional named argument, `Order`. This lets you change the order of `OnReady` method calls in `_Ready()`.\n\nThe calls in `_Ready()` are sorted by `Order`, from low to high. If two `OnReady` attributes have the same `Order` value (such as the default, `0`), the calls are sorted by the declaration order in the class file.\n\nAll `OnReadyGet` properties and fields are initialized before any `[OnReady(Order = 0)]` method is called.\n\nFor example, the following methods would normally be called from the top down (Two, One, Three), but `Order` makes them called in the order One, Two, Three:\n\n```cs\n[OnReady(Order = 2)] private void Two() =\u003e GD.Print(\"2\");\n[OnReady(Order = 1)] private void One() =\u003e GD.Print(\"1\");\n[OnReady(Order = 3)] private void Three() =\u003e GD.Print(\"3\");\n```\n\n---\n\n# Troubleshooting\n\n### error CS0111: Type '***' already defines a member called '_Ready' with the same parameter types\n\nThis means your script contains `override void _Ready() { ... }`. Instead, use [`[OnReady]`](#OnReady) with a different method name, for example, `Ready`:\n\n```cs\n[OnReady] private void Ready() { ... }\n```\n\nThis happens because GodotOnReady writes its own `public override void _Ready()`, and C# doesn't allow the same method to be overridden multiple times in the same class.\n\n### error CS0260: Missing partial modifier on declaration of type '***'; another partial declaration of this type exists\n\nYour class is most likely missing the `partial` modifier. The declaration\nshould look like this:\n\n```cs\npublic partial class MyNode : Node\n```\n\n### I don't have a error message, but it isn't working!\n\n* My variables are null even though they have `[OnReadyGet]` attributes!\n* `[OnReady]` methods aren't being called!\n* The `Path` properties don't show up in Godot!\n\nIf you hit one of those issues, it probably means the source generator didn't run.\nTry these steps:\n\n1. Hit the `Build` button at the top-right of the Godot editor to make sure your build is up to date.\n1. Make sure you are using [.NET SDK version 5.0](#Prerequisites) or newer.\n1. Make sure your [Build Tool is set to `dotnet CLI`](#Prerequisites).\n1. Are you seeing a problem in a CI build, even though it works fine on your own machine? [Your CI may be using a Mono SDK](https://github.com/abarichello/godot-ci/issues/80). Make sure it's using the .NET SDK.\n\nIf none of that works, please file an issue. Include the output of\nrunning `dotnet --info` on the command line, the Godot build log,\nand if possible, the project.\n\n# License\n\nGodotOnReady is licensed under the [MIT license](LICENSE).\n\n\n[C# Source Generator]: https://devblogs.microsoft.com/dotnet/new-c-source-generator-samples/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F31%2FGodotOnReady","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F31%2FGodotOnReady","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F31%2FGodotOnReady/lists"}