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 /
This question was closed Feb 28, 2014 at 06:06 PM by perchik for the following reason:

Problem is not reproducible or outdated

avatar image
2
Question by perchik · Feb 28, 2014 at 05:03 PM · c#transformcompilation

C# Extension method not found

I've written an extension method for UnityEngine.Transform but Unity doesn't like it. If I explicitly call the extension method, it works fine, but otherwise it doesn't.

Extension:


 using UnityEngine;
 using System.Collections;
 
 namespace CustomExtensions
 {
     public static class TransformExtender
     {
         public static UnityEngine.Transform FindRecursive
             (this UnityEngine.Transform t, string name)
         {
             return FindRecursive(name, t);
         }
 
         private static UnityEngine.Transform FindRecursive
             (string name, UnityEngine.Transform current)
         {
            //... Implementation of recursive search not relevant to the question...will post in comments if anyone cares.
            return null;
         }
     }
 }


Usage:


 using CustomExtensions;
 ...
 
 void Start(){
      Transform T = transform.FindRecursive("somegrandchild");
      Transform R = TransformExtender.FindRecursive(transform, "somegrandchild");
 }



The first usage gives me the error:

error CS1061: Type UnityEngine.Transform does not contain a definition for FindRecursive and no extension method FindRecursive of type UnityEngine.Transform could be found(are you missing a using directive or an assembly reference?)

The second usage works fine. For what it's worth, Visual Studio intellisense understands the extension. If I type transform.F it gives me the three options "Find, FindChild, FindRecursive(extension)" but for some reason the unity compiler doesn't like it.

Any ideas what I'm doing wrong?

UPDATE:

So, I was playing with it some more and it turns out that it does indeed work some of the time. In particular

Transform upperArm = transform.FindRecursive("upper_arm_R");

string joint = "upper_arm_R"; Transform upperArmB = transform.FindRecurisve(joint);

the first instance works, the second does not( throws the CS1061 error). I'm not sure why those would be different, but I believe the Extension is probably not the error...

"Extension method that takes a string works fine with string literal, but fails with variable of type 'string'" Any thoughts?

Comment
Add comment · Show 11
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 whydoidoit · Feb 28, 2014 at 05:19 PM 1
Share

Something to do with putting the static class in a normal folder and trying to use it from a Plugins folder? $$anonymous$$y Transform extender looks pretty much like yours and it works fine.

avatar image whydoidoit · Feb 28, 2014 at 05:22 PM 1
Share

Yeah and you're not using it from a folder under plugins - or some kind of Standard Assets or something?

avatar image whydoidoit · Feb 28, 2014 at 05:26 PM 1
Share

Right, well that's weird then. Be interested to hear if you can make it work with the rewrite... aAre you letting Unity build it or building it externally?

avatar image RickyAh · Feb 28, 2014 at 05:43 PM 1
Share

Is ALL that code defined in the same file?

avatar image whydoidoit · Feb 28, 2014 at 05:45 PM 1
Share

Not particularly. I avoid it

Show more comments

1 Reply

  • Sort: 
avatar image
-2

Answer by huntsfromshadow · Feb 28, 2014 at 05:13 PM

It's the namespace. Get rid of the namespace and it should work.

Also your second method doesn't have a 'this' argument in it's arguments.

Comment
Add comment · Show 8 · 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 perchik · Feb 28, 2014 at 05:17 PM 0
Share

$$anonymous$$y original code didn't have the namespace, and it didn't work:

 using UnityEngine;
 using System.Collections;
 
 public static class TransformExtender
 {
     public static Transform FindRecursive
         (this Transform t, string name)
     {
         return FindRecursive(name, t);
     }
 
     private static Transform FindRecursive
         (string name, Transform current)
     {
         //Implementation
         
         return null;
     }
 }


I added the namespace to try to explicitly include it in the usage file

avatar image huntsfromshadow · Feb 28, 2014 at 05:33 PM 1
Share

Is the name of the file of the TransformExtender the same as the name of the class? Is it TransformExtender.cs ?

avatar image huntsfromshadow · Feb 28, 2014 at 05:36 PM 1
Share

Only other thing I can think is maybe the Variable T is throwing the compiler in your monobehavior script as T most time is used by the generic system.

avatar image RickyAh · Feb 28, 2014 at 05:36 PM 1
Share

It is not a namespace problem. If it was, the second usage won't work either.

Also, the second method is not intended to be an extension method that's why it lacks the thisin the first parameter

avatar image huntsfromshadow · Feb 28, 2014 at 05:38 PM 1
Share

Yea I admit I'm stumped. I pulled your code into an empty project in 4.3.4 and it compiles fine.

Show more comments

Follow this Question

Answers Answers and Comments

23 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Unity's mouse look causing movement issues 1 Answer

Smooth out character movement? 4 Answers

stop object(door) translation 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