• 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 Griffo · Mar 17, 2014 at 03:18 PM · compiler

C# access .js then I want the .js to access the C#

Hi,

I have a .js that is accessed from a C# script so I placed my .js in plugins and all works fine, but I also want the .js to access the same C# script but is that possible because the .js is compiled first I get the error ..

The name 'TestScript' does not denote a valid type ('not found').

I put the .js in plugins to compile first so the C# script can see it and access it, but when I put a ref (TestScript) in the .js to the C# script I get the error.

Is this possible?

Thanks.

Comment
Add comment · Show 2
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 · Mar 17, 2014 at 05:43 PM 1
Share

You probably can't do that kind of circular reference... You might need to reevaluate what you're trying to accomplish (and/or translate one of the scrips to the other language)

avatar image robcbryant · Mar 17, 2014 at 06:17 PM 0
Share

I'm not sure what you're trying to do exactly--but one way to get around the problem:

If there is an update loop in your .js script you can do what you're trying to accomplish by creating variables for all the data you need from the C# script in the .js script. From the C# script, send that data to the .js script which acts upon it.

.js Script pseudo code:

 var a;
 var b;
 boolean cSharpTrigger = false;
 
 UpdateLoop{
   if(CSharpTrigger == true){ //do something 
   PrintToScreen(a + b);
   cSharpTrigger = false; //only do something once
   }
 }//end update loop
 
 function storeCSharpData(var A, var B){
 a = A;
 b = B;
 }

C# Script:

 String a = "Hello";
 String b = "World";
 SomeObjectWJSTestScript.GetComponent<TestScript>().storeCSharpData(a,b);

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Yokimato · Mar 17, 2014 at 06:26 PM

I think you're running into this issue due to an issue with design and encourage you to re-evaluate your design.

Beyond that, some info that sheds some light specifically related to this is:

  • js files are compiled before cs files

  • to get a cs script compiled before js, you'd have to add the cs script to a special folder, such as Standard Assets

The point is that one will be complied before the other in 2 different steps and thus you'll need to make the decision of which one is referencing which...but they can't both reference each other.

Another possible work around would be to convert your js script to c# or vice versa so that they can both be compiled during the same step.

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 Griffo · Mar 17, 2014 at 06:52 PM

Thanks everyone for the input, but the way I've decided to go is, make a globalVar.js holding all the variables that the C# and .js use and need to share, place it in the plugin folder to compile first, update it at Start() from each script, then use and update at runtime, then the two scripts can happily access and share the data.

The reason I don't want to convert one or the other is that the scripts are quiet large and access other scripts, so then I loose connection to other scripts, so it's a knock on effect.

Cheers.

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.

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

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Parser Error. 1 Answer

please help island demo compieler error 2 Answers

How to not compile un-used scripts ? 1 Answer

Scripting in inspector, possible? 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