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 Roarster · May 23, 2013 at 09:41 AM · androidlanguagebest practicestransfer

how to transfer data to unity efficiently

I'm in the early stages of programming a sort of adventure game. It's mostly based in java using android activities, but there's one activity that I embed unity in so I can get some awesome battle scenes :) I'm programming the unity side in c#. I've basically hit a bit of a mental block in my head. I know how to call c# methods from java and vice versa but I don't know how to do this efficiently with a lot of data. As I start the unity instance I need to send it the following data:

  • list of entities that the player and opponent has 'equipped'

  • list of items both of them have in their 'bag'

    Then for each entity things like:

  • health

  • moves the entity knows

  • more things like this as game evolves

I've got it all nailed down as classes in java and c# but obviously I can't send classes across different languages... So I'm stuck...

I also want to keep this all as DRY as possible, it'd be nice to not have to repeat things like item descriptions in java and the c#(as I'd like the user to be able to access their items in some android activities as well as inside unity)

Thanks

Comment
Add comment · Show 6
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 Fornoreason1000 · May 23, 2013 at 09:19 AM 1
Share

"unsure how to split code" isn't a valid title...

also if you want my advice I would convert the US Scripts to C#(or the other way around)... if your new to coding this can take FOREVER(about 35$$anonymous$$utes for Character$$anonymous$$otor for newbies). the reason i do this, is that I find it an utter pain trying to get two languages to cooperate when they compile at different times and ends up being a mess.

avatar image Roarster · May 23, 2013 at 10:42 AM 0
Share

@Fornoreason1000 all the unity scripts are already in C#... Is that what you're saying the best choice would be?

avatar image Tomer-Barkan · May 23, 2013 at 10:47 AM 0
Share

@Roarster it's not just the scripts... The C# scripts $$anonymous$$UST run from within the Unity player, which encapsulates the unity engine (physics, rendering, etc).

And anyway, when you use unity on android, it's always two languages, because android runs natively on Java, and unity doesn't. So even when you create the project directly from unity, it encapsulates the unity engine with a java class.

avatar image Fornoreason1000 · May 23, 2013 at 10:47 AM 0
Share

@Roarster Not all of them... Character $$anonymous$$otor, FPSController, most of the image effects are in Unity Script... As for Languages there is no "Best Choice" its a personal preference. I was just saying that mixing two languages in one project can do your head in if your aren't careful.

@tbkn Unity Converts both C# in US into its own language(C++?) just at different times, I assume It won't matter once the engine runs on Android since everything should be pre-compiled at that point before doing the Java buisness.

avatar image Roarster · May 23, 2013 at 11:03 AM 0
Share

@Fornoreason1000 right, I see, so you're saying I should recode the standard unity scripts that I'm using to c# so that everything in the project is in c#? Isn't that just overkill, considering there are so many guides for using unity in android and none of them mention this issue?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Tomer-Barkan · May 23, 2013 at 09:53 AM

I'd say the best way to transfer data to unity would be to write them to a text file in temp directory, and then let unity read that text file when it loads.

Note that I'm not sure your solution is such a good one, since loading unity player on mobile devices could take some time, and it would be annoying for the player to wait for it to load before every battle.

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 Roarster · May 23, 2013 at 11:07 AM 0
Share

Ok, I'll try that. I guess I could also use JSON to transfer data between the two once it's running too. I'll see how long it takes to load, but I don't see any reason it should take much longer than a few seconds - it's not 3D, I'm using a few sprites and I've looked at a few videos of unity loading on android devices and they don't take very long...

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

15 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

Related Questions

A node in a childnode? 1 Answer

Unity Game Controllers syncing with iPhone or Android 1 Answer

Mulitplayer Game in Unity 1 Answer

Unity / QCAR Activity on Android 1 Answer

Onmouse event handlers preventing me from building an apk? 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