- Home /
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
"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.
@Fornoreason1000 all the unity scripts are already in C#... Is that what you're saying the best choice would be?
@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.
@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.
@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?
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.
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
Follow this Question
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