Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by gardian06 · Apr 12, 2013 at 03:07 PM · .netdelegate

Lifespan of a Delegate with respect to the Container

I am currently working on a shooter, and want to have a common projectile class, and then have each weapon have its own effect. so each WeaponClass that derives from WeaponBase (abstract base class) will override a delegate implementation.

then the Projectile will have an instance of that delegate that will be handed to the receiver, to actually apply the effect.

if ObjectA holds a reference to a delegate defined in a class on ObjectB. what happens when ObjectB is destroyed (released for garbage collection), and in addition what happens if ObjectA handed that same delegate reference to an ObjectC (to run the delegate over a series of loops)

Comment
Add comment · Show 8
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gardian06 · Apr 12, 2013 at 03:09 PM 0
Share

for the final paragraph it can be assumed that ObjectA will also be destroyed as well after the delegate reference is passed.

avatar image fafase · Apr 12, 2013 at 03:12 PM 0
Share

I don't really get it, what you show is not a delegate but an abstract method, still you talk about it like a delegate.

avatar image gardian06 · Apr 12, 2013 at 03:48 PM 0
Share

the abstract method matches the signature of a delegate defined externally which is completely legal.

avatar image Bunny83 · Apr 12, 2013 at 04:08 PM 0
Share

@gardian06: Hmm, why have you included a line that isn't actually related to the problem, but the actual delegate is not there.

avatar image gardian06 · Apr 12, 2013 at 05:25 PM 0
Share

edited to clear up confusion.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by whydoidoit · Apr 12, 2013 at 03:13 PM

When ObjectB is "Destroyed" will cause ObjectB to start to return null when referenced (thanks to some internal Unity magic), this could well cause your Delegate to fail.

Destroying a game object causes problem in Unity compared to normally losing a reference as you would in C# in a traditional .NET setting (where it would still be reachable and therefore valid).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Delegate does not contain a definition for 'CreateDelegate' 1 Answer

Capturing a variable in a closure behaves differently in Unity 2 Answers

Problem with FileStream 1 Answer

30f + 0.5f = 30f What?????? 1 Answer

ASP .NET: How do I link gui components to Unity web player? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges