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 oskilian · Jul 07, 2011 at 11:09 AM · c#javascriptparameter

Passing a parameter by reference from JavaScript

I'm using a third party library written in c#, which has some functions that go like this:

 void SomeFunction(ref string someParameter)

How can I call this function from JavaScript? I'm getting a parameter mismatch if I just put the variable in the caller.

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 Eric5h5 · Jul 07, 2011 at 06:41 PM

Sounds like your variable isn't the correct type? Because it works fine just calling a function and using the variable without "ref" in JS. e.g.,

 using UnityEngine;
 
 public class Test {
     public static void StringTest (ref string test) {
         test = "abc";
     }
 }

And then with JS:

 var test = "123";
 Test.StringTest (test);
 Debug.Log (test);
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 oskilian · Jul 11, 2011 at 09:44 AM 0
Share

I'm pretty sure the type was okay. The error went something like "Cannot convert from SomeClass to ref SomeClass". Anyways, we solved it by moving the caller to c#, so I can't test this answer, but I don't want to get flamed for not marking answers, so I'll mark this as the correct one.

avatar image
0

Answer by GuyTidhar · Jul 07, 2011 at 06:14 PM

You can do that directly but you may use some wrapper to achieve this:

 // A C# Wrapper which you can name "StringHandler.cs"
 public class StringHandler
 {
    public void WrapperFunction(string[] str)
    {
       // If you string need to be empty DO:
       string localStr = "";
       // Or if your string should have some data DO:
       string localStr = str[0];

       // Now call the third party stuff
       ThirdPartyStuff.SomeFunction(ref localStr);
         
       str[0] = localStr;
    }
 }

Now, in your javascript do stuff like the following:

 var stringHandler : StringHandler;
 
 function Start()
 {
     var myStr : String[] = [ "YouBaseTextIfNeeded" ];
 
     Debug.Log("1) myStr = " + myStr[0]);
 
     stringHandler = new StringHandler();
 
     stringHandler.WrapperFunction(myStr);
 
     Debug.Log("2) myStr = " + myStr[0]);
 }
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 Eric5h5 · Jul 07, 2011 at 06:44 PM 0
Share

That's not necessary at all.

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Pairing and GUITexture with a Timer? 1 Answer

How do i fix "Script does not exist" error when trying to add my script to something 3 Answers

About "translating" js into C# 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