Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by RobAllen · Oct 18, 2016 at 06:14 PM · unity 5behaviorextension-methods

Unable to load script, when referencing an extension method

I have a really simple extension method that I am calling from a MonoBehavior. When I use the method the Unity project fails to compile and states that the Behavior that is using the extension method can not be loaded, please fix compile errors and assign a valid script.

I've included the commented code in the behavior that works if I comment out the extension method call.

There are no errors in the Visual Studio project, and everything appears to be in order.

The extension class:

 public static class TransformExtensions
 {
     public static void Clear(this Transform transform)
     {
         foreach (Transform child in transform)
         {
             Clear(child.transform);
             GameObject.Destroy(child.gameObject);
         }
 
         GameObject.Destroy(transform.gameObject);
     }
 }

The behavior

 public partial class MeasureManager : Singleton<MeasureManager>
 {
         void DeleteMeasurement(Measurement measurement)
         {
             //while (measurement.Container.transform.root.childCount > 0)
             //{
             //    DestroyImmediate(measurement.Container.transform.root.GetChild(0).gameObject);
             //}
             //DestroyImmediate(measurement.Container.transform.gameObject);
 
             measurement.Container.transform.Clear();
 
             Measurements.Remove(Measurements.Find(x => x.Name == measurement.Name));
             _current = null;
         }
 }


Comment
Add comment
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

2 Replies

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

Answer by RobAllen · Oct 21, 2016 at 04:15 PM

In the end, this was a namespacing issue. I was piggy backing off some of the HoloLens Toolkit code and was using their namespace. For some reason this caused problems when trying to access my extension methods that we're not in the same or no namespace.

I don't understand why Unity took issue, when Visual Studio resolved everything correctly.

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

Answer by JoshuaMcKenzie · Oct 21, 2016 at 04:46 AM

I'm going to hazard a guess that Clear(child.transform) should be child.transform.Clear(). With the code you've provided, it shouldn't even compile in Visual Studio...

the method Clear(Transform transform) is not defined (which is completely separate from Clear(this Transform transform))

also if Unity says that its failing to load a Behaviour script that usually a sign that the filename doesn't match the class name. Also only one Behaviour should be in a file. If you have multiple Behaviours in the same file (even if at least one matches the filename) Unity will fail to compile due to the other Behaviours not having their own file

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 RobAllen · Oct 21, 2016 at 03:47 PM 0
Share

thanks for trying to help. I'm certain that you've come to your conclusions because I didn't add the complete code as I was attempting to be succinct. Rest assured there is only one behavior in my files and that the code certainly compiles. The behavior name is also correct.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Change calling object with extension method 1 Answer

GetComponent, What is it ? 1 Answer

aspect ratio vs fixed resolution [HELP PLEASE] 2 Answers

Authentication Error Whenever i hit the Azure link in unity to download models 0 Answers

Strange behavior of RigidBody2D 1 Answer


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