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 /
avatar image
1
Question by zgarbowitz · Oct 26, 2011 at 10:45 PM · c#compilereval

Compilation Order question when using js eval()

Hi all,

I have a question regarding the Unity compilation order. I've read all of the information at http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html about script compilation, and understand that. My problem is that I am using a dialogue engine written in js, where the rest of my game is written in C#.

All of the js code is contained in Standard Assets, so it will be compiled first. Then all of the C# code is contained in the Resources folder, so it is compiled after the js. In this way the C# can reference the js, but not the other way around.

My problem is that I need the dialogue engine, written in js, to be able to check game state variables that are in the C# part of the code. I was hoping to do this through the use of the eval() function, which allows you to execute code input in the form of a string. My thinking was that the eval call does not occur until run time, and so by that point both the js and C# should be compiled and so code in the eval should be able to reference either one.

I have verified that the eval is not called until runtime, however I still receive an error:

CompilationErrorsException: script(1,1): BCE0005: Boo.Lang.Compiler.CompilerError: Unknown identifier: 'DramaDebugger'

The code being executed in the eval statement is:

DramaDebugger.Instance.LogMessage("loggingscript");

DramaDebugger is a C# singleton class I have defined. Does anyone have any suggestions or ideas as to why this is still throwing a compiler error? Because I know that DramaDebugger has already been compiled by the time the eval call occurs.

Sorry for the long post, and let me know if anything is unclear or you need more information. Thanks!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by luizgpa · Dec 01, 2011 at 05:22 PM

Unity compiles the code in different assemblies. When the eval is executed, it searches for a class named DramaDebugger but can't find it, because it's only defined on other assembly.

You could load this assembly in the JS code and call the method using reflection, but I don't know a good way to manually load the assemblies generated by Unity.

Or you could pass a reference to the singleton instance, in the C# code, and use it int the JS. Eg:

JSClass.js


 var dramaDebuggerinstance;
 
 ...
 
 dramaDebuggerinstance.LogMessage("loggingscript");

 


and in the DramaDebugger.cs:

 (FindObjectOfType(typeof(JSClass)) as JSClass).dramaDebuggerinstance = 
                                                          DramaDebugger.Instance;



Just take care to pass the reference for every object you will need before using it.

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Compiler error - wrong target 1 Answer

Temporarily disable gamepad button 1 Answer

Play specific animation in mechanim 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