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 Aboo · Feb 15, 2011 at 01:46 AM · javascriptarrayclientsendmessage

Problem sending array to unity player using SendMessage

Hi,

I am trying to call the SendMessage function in order to call a method within unity player from web browser and I want to pass an array of integers or array of bytes. It works only if the length of the array is less than 1024. When the length of the array goes more than 1024 then I receive :

Error calling method on NPObject!

A sample code is like this:

var a = new Array();
var i = 0;
for (i = 0; i < 1025; i++) {
   a[i] = i;
}
unity.SendMessage("MyObject", "MyMethod", a);

The method within unity player is like this:

void MyMethod(Array array)
{
  Debug.Log("received array length : " + array.Length);
}

As I mentioned everything works as expected until the length of the array will be more than 1024. However if I pass a string it could be very long. I tested a string with length 1,000,000 and it worked. Unfortunately in my case I need the array and converting the string back to array will significantly affect the performance.

Any idea?

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 fireDude67 · Feb 15, 2011 at 01:48 AM 0
Share

Perhaps divide the data?

avatar image Aboo · Feb 15, 2011 at 02:01 AM 0
Share

Even dividing the data when I have more that 400,000 items in each array will cause performance issue.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tertle · Feb 15, 2011 at 02:49 AM

I was going to write this as a comment but got to long.

The fact it's the magic number of 1024 I'm going to assume it's just a engine problem with either SendMessage or Array.

So how many components are you sending this to? Seems kind of poorly designed/inefficient if you ask me if you need to send such a large amount of data to a large number of places. If it's just a single other script you should really just get a direct reference to it.

Also out of interest, if you encapsulate the array it in another class and send the class does it still cause the same issue?

Finally, have you considered trying an ArrayList instead? Or just a basic native .NET arrays if you don't need to resize it (assuming above code isn't what is in your game.) I don't really like the built in Unity Array.

-edit-

Getting another script, where otherscript is the name of the script you are sending the stuff to.

OtherScript other = FindObjectOfType(typeof(OtherScript));
other.MyMethod(a);

If other script is attached to same object can just do.

GetComponent(OtherScript).MyMethod(a);

Or if you want to get it off a specific gameobject

var go = GameObject.Find("SomeGuy");
go.GetComponent(OtherScript).MyMethod(a);

You shouldn't do a Find every update for performance reasons, but you can do it once in Start() and just store it and call it anytime you want.

Comment
Add comment · Show 3 · 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 Aboo · Feb 15, 2011 at 03:19 AM 0
Share

Thanks for your reply.

Please note that I am calling the Send$$anonymous$$essage from javascript within client browser. So I don't have a .Net array or ArrayList in client side javascript.

The problem is even before reaching unity player and at the script level. It looks like that the Send$$anonymous$$essage method in client side can not handle arrays of length more than 1024.

I am calling only one component and I don't know what do you mean by getting a direct reference.

avatar image tertle · Feb 15, 2011 at 03:50 AM 0
Share

edited an example of finding another script.

avatar image Aboo · Feb 15, 2011 at 08:27 AM 0
Share

I appreciate your time but this looks like a code written to be run inside unity player. I have no problem at this stage. What I am doing is trying to call the method via web browser Javascript.

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

1 Person is following this question.

avatar image

Related Questions

Web Player SendMessage Array Parameters 1 Answer

ExecutionEngineException: SIGILL 0 Answers

How to deactivate gameObjects instead of destroying them ? 1 Answer

JS: Display Array contents in a Box 0 Answers

How to acquire an associative array from the client? 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