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
0
Question by Aubrey-Falconer · Dec 22, 2011 at 07:23 PM · pluginscommunicationcompilationjs-c#-together

Compilation Order Quandaries - Cross Language Game-To-Library Communication

I have a library of JS scripts which need to be included in Unity's main compilation pass, so they are stored under the /Extensions folder. (I already spent a day trying to get the library running smoothly in a higher compilation pass, but between AssetBundles referencing scripts in the library and other arcane dependencies, it just isn't working out...)

I am now rewriting my game in C#, and a fair amount of functions and members of the library need to be accessible to my game. Note: in case this makes any difference, I have already redesigned the library so that everything which the game needs to access is contained within a couple Singleton monobehaviours which will always be present (their GameObject is DontDestroyOnLoad.

What is the best way to enable Game > Library function calls and Game < Library state variable access? I am planning to set up an "interface" script for my library in the /Plugins folder, which will be used for all communication between my game and the library. My options from there seem to be threefold:

(1) Store a static reference to each singleton monobehaviour in the Interface script. If this is possible, it would be awesome! I could work with the library directly from my game. Haven't yet figured out how to overcome the compilation pass barrier and achieve this.

(2) Use some form of reflection in the interface script to act as a go-between for each function and state variable in the library. I've been able to find a couple examples of reflection (such as here: http://forum.unity3d.com/threads/26762-Dynamic-typing-in-C?p=176056&viewfull=1#post176056 ), but am still not totally familiar with what it is capable of. (Would Eval() be of any help?)

(3) Use a bunch of SendMessage calls in the interface script to relay to functions calls in the library. Not sure how to read state variables back from the library. I have heard people speak of passing object references with SendMessage, but can't find many examples of this. Could a passed ObjectReference overcome the compilation pass barrier? (This exact question is posed - but never answered - in the bottom of this thread: http://forum.unity3d.com/threads/13858-Combining-Javascript-with-C )

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
Best Answer

Answer by Aubrey-Falconer · Dec 23, 2011 at 06:31 PM

The more I think about this (it can really help to write out the problems you are facing, then come back a day later and analyze them afresh), it seems that I can solve everything with Occam's razor. Instead of trying to use advanced coding techniques to reference state variables from inside the library using my interface script, I should just move all state variables into the interface script to start with! The library can update them there as necessary, and the rest of my game will be able to read them effortlessly as well. I'll use SendMessage to forward requisite interface calls to internal parts of the library as necessary, and live happily ever after.

If anyone would like to chime in with some other ways I could have accomplished this using more advanced coding techniques, I would love to hear them. If noone does, I'll mark this as answered in a couple days.

Regardless, this answers system forced me to write down my problem as clearly as I could, without which prompting I know not how long it would have taken me to perceive the obvious. For this, I am truly thankful.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to build a plugin before the compilation of scripts? 0 Answers

What are the rules for the Plugins folder in Unity 5? 0 Answers

CommandInvokationFailure: Failed to re-package resources when added GooglePlayGames plugin 2 Answers

Why does my editor throw an error using firebase plugin? 1 Answer

No BoundService Google Play Services 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