• 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 Sprite101 · May 05, 2012 at 09:32 PM · namespace

Action or Func<,> delagations

I seem to be having trouble accessing the namespace for Func or Action... anyone know what namespace I'm supposed to be using?

Comment
Add comment · Show 1
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 Berenger · May 05, 2012 at 10:20 PM 0
Share

script language ?

2 Replies

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

Answer by Sprite101 · May 05, 2012 at 11:33 PM

Its in C#, but I discovered its in the namespace System. Its just not recognized as a keyword by MonoDevelop

Comment
Add comment · Show 1 · 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
avatar image Berenger · May 06, 2012 at 01:50 PM 0
Share

What are you trying to do exactly ?

avatar image
4

Answer by sinjimonkey · Dec 25, 2014 at 07:12 AM

The first answer helped me solve the same question. For anyone else that comes across this, adding "using System;" will allow Func<> and Action<> to be recognized in MonoDevelop (Or use System.Func<> and System.Action<>)

Comment
Add comment · Show 4 · 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
avatar image illustir · Sep 23, 2015 at 12:59 PM 0
Share

Thanks! But that still won't work since Unity itself uses UnityAction which $$anonymous$$onodevelop also can't resolve…

avatar image Sprite101 illustir · Sep 23, 2015 at 02:14 PM 1
Share

This thread is over a year old, when UnityAction wasn't even a thing.

There's nothing wrong with using Action<,> or Func<,> or System.Event or delegate... you just can't plug them in through the inspector. I don't even remember why I was trying to do this in the first place.

avatar image illustir · Sep 23, 2015 at 02:33 PM 0
Share

This was the only thing I could find about getting this to work. It turns out you can't pass a bare Action to AddListener() either, so I get this:

     public GameObject AddButton(string text, Action callback) {
         GameObject button = this.AddButton(text);
 
         button.GetComponentInChildren<Button>().onClick.AddListener(() => {
             callback();
         });
 
         return button;
     }
avatar image Sprite101 illustir · Sep 23, 2015 at 02:39 PM 0
Share

I do something similiar in my object loaders if I want to get a callback on completion or a progress callback. I wrote a custom IEnumerator to handle that stuff:

 public abstract class Loader : IEnumerator {
 
     protected Action completedCallback;
 
     public delegate void ProgressCallback(float progress, string processName);
     protected ProgressCallback progressCallback;
 
     protected abstract float GetProgress();
     protected abstract string GetProcessName();
 
     protected Loader(){}
 
     #region IEnumerator implementation
     public abstract bool $$anonymous$$oveNext();
 
     public abstract void Reset();
 
     public abstract object Current
     {
         get;
     }
     #endregion
 
 }

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

Which namespaces are supported in each platform? 1 Answer

private void GenerateUV (Decal) {The type or namespace 'Decal could not be found (are you missing a using directive or an assembley referance?) 0 Answers

Unity 4.0 warning about "The class defined in script file name 'X' does not match the file name!" when using namespaces 2 Answers

Preventing namespace errors and other anomalies 0 Answers

The type or namespace name could not be found. Are you missing a using directive or an assembly reference? 4 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