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 /
This question was closed Jul 10, 2016 at 06:22 PM by Droidenkiller for the following reason:

Other

avatar image
0
Question by Droidenkiller · Jul 08, 2016 at 03:53 PM · c#errortransformvisual studiomonobehaviour

The name 'transform' does not exist in the current context (Fixed, was my fault)

EDIT: I accidentaly created a new public class named MonoBehaviour so this was my own fault and it is fixed now. Thanks to everyone who tried to help.

Can someone please explain to me why this code is giving me the error "CS0103: The name 'transform' does not exist in the current context' in Visual Studio?

 using UnityEngine;
 using System.Collections;
 
 public class test : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
         transform.position = Vector3.zero;
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
 

I created this class as a test but I have multiple other classes that give me the same error in Visual Studio and in Unity as well. Some months ago the project worked perfectly fine.

EDIT: After restarting, the error now doesn't show up in Unity anymore and I can add the affected scripts to a GameObject again but the error is still present in VisualStudio.

EDIT 2: It reappeared in Unity after I changed the name of the test class and it's file. But it only appeared for the test class.

Comment
Add comment · Show 3
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 Dave-Carlile · Jul 08, 2016 at 05:54 PM 0
Share

Interesting. Do you have other classes that don't have this problem? Does the class name match the file name? Try rena$$anonymous$$g both to something other than Test. Close everything and back everything up, then delete the Library folder and re-open.

avatar image Droidenkiller Dave-Carlile · Jul 08, 2016 at 06:15 PM 0
Share

Rena$$anonymous$$g the file and class (matching names (as before)) didn't work and deleting the Library folder and re-opening it also didn't work. But now it warns me of inconsistent line endings and that they can produce incorrect compile errors, so I will fix that now and see if this was the problem.

EDIT: Fixing the line endings didn't help.

avatar image Whiteleaf · Jul 08, 2016 at 07:21 PM 0
Share

Try recreating the script. Unity has this weird problem where it won't recognize certain things.

3 Replies

  • Sort: 
avatar image
0

Answer by JackTenSeven · Jul 08, 2016 at 04:40 PM

Could be that the script isn't assigned to a game object and so there is no parent to the script (transform). To fix it you could add the script as a component to any games object in unity and then that game object would be the transform for that script.

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 Droidenkiller · Jul 08, 2016 at 05:40 PM 0
Share

I don't think that's the problem as I'm not even able to assign it to a GameObject. It gives me a message saying "Please fix compile errors before creating new script components." I think transform is just a member of $$anonymous$$onoBehaviour so it shouldn't have any issues if it is not assigned to a GameObject.

avatar image
0

Answer by tanoshimi · Jul 08, 2016 at 07:18 PM

And what if you use the fully-qualified version?

 GetComponent<Transform>.position = Vector3.zero;
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 Droidenkiller · Jul 08, 2016 at 08:05 PM 0
Share

That gives me pretty much the same error just with GetComponent ins$$anonymous$$d of transform. Also gameObject is unknown and yields the same error.

avatar image
0

Answer by Droidenkiller · Jul 08, 2016 at 09:53 PM

I found the error.

I wanted to do some unit testing but it threw an Exception so I tried this solution:

https://community.unity.com/t5/Editor/Security-Exception-ECall-methods-must-be-packaged-into-a-system/td-p/696943

It kept giving me an exception so I removed the preprocessor directives and then this happened.

Thanks to everyone for trying to help.

If anyone has a solution to the problem in the link, I'd be interested in your solution.

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

Follow this Question

Answers Answers and Comments

8 People are following this question.

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

Related Questions

No Monobehaviour script in the file error Unity 2019.2 2 Answers

How do i fix Error CS0029? 1 Answer

"The class named is not derived from MonoBehaviour or ScriptableObject!", although class is derived from MonoBehaviour 2 Answers

Error CS0029: Cannot implicitly convert type to UnityEngine.UI.Transform 1 Answer

No Monobehaviour scripts in files 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