René's URL Explorer Experiment


Title: Naked delegates should have event modifier keyword · Issue #3137 · Unity-Technologies/com.unity.netcode.gameobjects · GitHub

Open Graph Title: Naked delegates should have event modifier keyword · Issue #3137 · Unity-Technologies/com.unity.netcode.gameobjects

X Title: Naked delegates should have event modifier keyword · Issue #3137 · Unity-Technologies/com.unity.netcode.gameobjects

Description: com.unity.netcode.gameobjects/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs Line 23 in dcaeef9 public OnValueChangedDelegate OnValueChanged; Delegate events like the one shown above should have event keyword mo...

Open Graph Description: com.unity.netcode.gameobjects/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs Line 23 in dcaeef9 public OnValueChangedDelegate OnValueChanged; Delegate events like the one ...

X Description: com.unity.netcode.gameobjects/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs Line 23 in dcaeef9 public OnValueChangedDelegate OnValueChanged; Delegate events like the one ...

Opengraph URL: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Naked delegates should have event modifier keyword","articleBody":"https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/dcaeef9ab7271c8e25081b484f9cb0be34294ecd/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs#L23\n\nDelegate events like the one shown above should have `event` keyword modifiers.\n\n```csharp\n public event OnValueChangedDelegate OnValueChanged; \n```\n\n--- \n\nA \"naked\" delegate refers to a delegate that is declared without the `event` keyword. This means the delegate is exposed directly, allowing external code to not only subscribe and unsubscribe to it but also to reassign or invoke it directly. This can lead to unintended side effects and potential bugs.\n\nFor example, in the provided code snippet, the delegates are correctly declared as events:\n\n```csharp\npublic event Action OnSpawnedLocal;\npublic event Action OnSpawnedAll;\npublic event Action\u003cNetworkPlayer> OnDisconnected;\n```\n\nIf these were declared as naked delegates, they would look like this:\n\n```csharp\npublic Action OnSpawnedLocal;\npublic Action OnSpawnedAll;\npublic Action\u003cNetworkPlayer> OnDisconnected;\n```\n\n**Issues with naked delegates:**\n\n1. **Reassignment**: External code can reassign the delegate, potentially removing all existing subscribers.\n   ```csharp\n   networkPlayer.OnSpawnedLocal = SomeMethod; // Reassigns the delegate, removing all previous subscribers.\n   ```\n\n2. **Invocation**: It breaks encapsulation, making it harder to control how and when the delegate is invoked.\n   ```csharp\n   networkPlayer.OnSpawnedLocal?.Invoke(); // Invokes the delegate from outside the class.\n   ```\n\n3. **Dangling Pointers**: Events in C# are multicast delegates which can have multiple and anonymous methods subscribe to the same event. Using the event keyword will help properly manage those subscriptions and unsubscriptions. This way if someone forgets to unsubscribe, the dangling pointer will get properly cleaned up by garbage collector.\n  - If a delegate holds a reference to an object that should be garbage collected, it can prevent the object from being collected, leading to memory leaks.\n  - If the target method or object of a delegate has been collected, invoking the delegate can result in a NullReferenceException or other runtime errors.\n\nTR;DL:\n\nI've seen this [throughout the whole codebase](https://github.com/search?q=repo%3AUnity-Technologies%2Fcom.unity.netcode.gameobjects+%22public+On%22&type=code) and highly encourage the use of the `event` keyword for all usages of delegate callbacks.\nUsing the `event` keyword ensures that the delegate can only be invoked from within the class that declares it, maintaining proper encapsulation and control over the event's lifecycle and avoiding memory pressure from forgetting to unassign the delegates after use.","author":{"url":"https://github.com/StephenHodgson","@type":"Person","name":"StephenHodgson"},"datePublished":"2024-11-22T17:16:44Z","url":"https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:c3247ff1-3f82-61f9-a9c7-274b3c364f11
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9110:215B38:5AB698:7BA184:6B00744B
html-safe-nonce6c7b88407e24b661fa1c78ddffec4c244651f23a42c895223ddf665ac2c6d11f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MTEwOjIxNUIzODo1QUI2OTg6N0JBMTg0OjZCMDA3NDRCIiwidmlzaXRvcl9pZCI6Ijc5MTgzNDI3NzI2MDY2NjE3MDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacee9b63e41a02203c08a29a757b2dca294be4bbdcc35a2c9cb777cc43c0864528
hovercard-subject-tagissue:2683955791
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/Unity-Technologies/com.unity.netcode.gameobjects/3137/issue_layout
twitter:imagehttps://opengraph.githubassets.com/8da02eb7cbf186aa0eb599ea850e7cf90617ac992ffdd3edb919b27b615883bb/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/8da02eb7cbf186aa0eb599ea850e7cf90617ac992ffdd3edb919b27b615883bb/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137
og:image:altcom.unity.netcode.gameobjects/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs Line 23 in dcaeef9 public OnValueChangedDelegate OnValueChanged; Delegate events like the one ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameStephenHodgson
hostnamegithub.com
expected-hostnamegithub.com
None75c2b65dd205f26961d0c29afed1a8d0bb7cca9f05780571dfd1ef93eb539d16
turbo-cache-controlno-preview
go-importgithub.com/Unity-Technologies/com.unity.netcode.gameobjects git https://github.com/Unity-Technologies/com.unity.netcode.gameobjects.git
octolytics-dimension-user_id426196
octolytics-dimension-user_loginUnity-Technologies
octolytics-dimension-repository_id116385203
octolytics-dimension-repository_nwoUnity-Technologies/com.unity.netcode.gameobjects
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id116385203
octolytics-dimension-repository_network_root_nwoUnity-Technologies/com.unity.netcode.gameobjects
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release84e563eb4b55f8fa102f325f117533cee9e3df4a
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FUnity-Technologies%2Fcom.unity.netcode.gameobjects%2Fissues%2F3137
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FUnity-Technologies%2Fcom.unity.netcode.gameobjects%2Fissues%2F3137
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=Unity-Technologies%2Fcom.unity.netcode.gameobjects
Reloadhttps://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137
Reloadhttps://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137
Reloadhttps://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137
Unity-Technologieshttps://github.com/Unity-Technologies
com.unity.netcode.gameobjectshttps://github.com/Unity-Technologies/com.unity.netcode.gameobjects
Codehttps://github.com/Unity-Technologies/com.unity.netcode.gameobjects
Issues35 (35)https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues
Pull requests27 (27)https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/pulls
Actionshttps://github.com/Unity-Technologies/com.unity.netcode.gameobjects/actions
Security and qualityhttps://github.com/Unity-Technologies/com.unity.netcode.gameobjects/security
Insightshttps://github.com/Unity-Technologies/com.unity.netcode.gameobjects/insights
https://github.com/Unity-Technologies/com.unity.netcode.gameobjects
New issuehttps://github.com/login?return_to=https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137
New issuehttps://github.com/login?return_to=https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137
Naked delegates should have event modifier keywordhttps://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137#top
type:feedbackIssue contains feedback and not specific bug or feature requests.https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues?q=state%3Aopen%20label%3A%22type%3Afeedback%22
https://github.com/StephenHodgson
StephenHodgsonhttps://github.com/StephenHodgson
on Nov 22, 2024https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137#issue-2683955791
com.unity.netcode.gameobjects/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cshttps://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/dcaeef9ab7271c8e25081b484f9cb0be34294ecd/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs#L23
dcaeef9https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/commit/dcaeef9ab7271c8e25081b484f9cb0be34294ecd
throughout the whole codebasehttps://github.com/search?q=repo%3AUnity-Technologies%2Fcom.unity.netcode.gameobjects+%22public+On%22&type=code
StephenHodgsonhttps://github.com/StephenHodgson
stat:awaiting-triageStatus - Awaiting triage from the Netcode team.https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues?q=state%3Aopen%20label%3A%22stat%3Aawaiting-triage%22
type:feedbackIssue contains feedback and not specific bug or feature requests.https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues?q=state%3Aopen%20label%3A%22type%3Afeedback%22
on Nov 22, 2024https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137#event-15401217547
https://github.com/NoelStephensUnity
NoelStephensUnityhttps://github.com/NoelStephensUnity
on Dec 10, 2024https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137#issuecomment-2530086324
https://github.com/StephenHodgson
StephenHodgsonhttps://github.com/StephenHodgson
on Dec 10, 2024https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137#issuecomment-2530193161
https://github.com/StephenHodgson
StephenHodgsonhttps://github.com/StephenHodgson
on Dec 10, 2024https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137#issuecomment-2530195945
https://github.com/NoelStephensUnity
NoelStephensUnityhttps://github.com/NoelStephensUnity
on Mar 31, 2025https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137#issuecomment-2767200907
NoelStephensUnityhttps://github.com/NoelStephensUnity
stat:InvestigatingIssue is currently being investigatedhttps://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues?q=state%3Aopen%20label%3A%22stat%3AInvestigating%22
stat:awaiting-triageStatus - Awaiting triage from the Netcode team.https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues?q=state%3Aopen%20label%3A%22stat%3Aawaiting-triage%22
on Mar 31, 2025https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137#event-17062813912
michalChrobothttps://github.com/michalChrobot
stat:awaiting-responseAwaiting response from author. This label should be added manually.https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues?q=state%3Aopen%20label%3A%22stat%3Aawaiting-response%22
on Apr 1, 2025https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137#event-17076685672
michalChrobothttps://github.com/michalChrobot
stat:awaiting-responseAwaiting response from author. This label should be added manually.https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues?q=state%3Aopen%20label%3A%22stat%3Aawaiting-response%22
on Apr 10, 2025https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137#event-17202360166
NoelStephensUnityhttps://github.com/NoelStephensUnity
stat:InvestigatingIssue is currently being investigatedhttps://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues?q=state%3Aopen%20label%3A%22stat%3AInvestigating%22
on Apr 14, 2025https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137#event-17252880149
Sign up for freehttps://github.com/signup?return_to=https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137
Sign in to commenthttps://github.com/login?return_to=https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3137
type:feedbackIssue contains feedback and not specific bug or feature requests.https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues?q=state%3Aopen%20label%3A%22type%3Afeedback%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.