• 10
• 13
• 18
• 27
• 9
• ### Similar Content

• While looking out for that pesky Terrator, our little alien is doing a bit of relaxed mining down on the new gas planet "Lelantos" this weekend....

• I have a native iOS game (objective c, XCode build) which I am considering to port to other platforms.
Core gameplay is based on solely on geographical maps, and custom drawing over maps. It also has Core Data. This part is complete in development.
What is not done yet is: monetization, gamification (leaderboards, challenges) and multiplayer functionality.
As I think more about it, I am tempted to think if this is the right time to move to a cross platform tool such as Unity. But before dedicating time to port my 5 years side-project effort in Objective C, I really want to know if its worth it.
- Does Unity support such plugins / assets that will fulfill all my above requirements?
- Unity Personal seems to have only 20 concurrent users - is it too costly scaling if I decide for extending to web and android platforms?
- What is the general workflow involved in publishing to iOS, Android, PC, and web platforms while using Unity? I mean to ask about various points of signing stuff, paying fees and getting certified.
- How long will it really take to port my entire Objective C project into Unity? I am somewhat familiar with C# but I am finding it hard fidgeting with Unity IDE as lot of things are focused around FPS and 3D while my game is still 2d - not much action involved. I seem bit overwhelmed by the list of features I see there. All in all, I do not want to lose my momentum while still making sure its portable to everywhere.
- Any assets I could use (for free to try basis in debug) that are relevant for my game?
- Last but not the least, are there any costs that I need to be paying upfront to Unity, for using it (apart from their monthly subscription model)? I don't understand their costing for multiplayer in conjunction with their subscription fees - if someone could kindly elaborate.
• By GytisDev
Hello,
me and few friends are developing simple city building game with unity for a school project, think something like Banished but much simpler. I was tasked to create the path-finding for the game so I mostly followed this tutorial series up to episode 5. Then we created simple working system for cutting trees. The problem is that the path-finding is working like 90% of the time, then it get stuck randomly then there's clearly a way to the objective (tree). I tried looking for some pattern when it happens but can't find anything. So basically I need any tips for how I should approach this problem.
Use this image to visualize the problem.
• By aymen
please any know how can i' calculate the centroid from any number vertices

• Good day sir/maam. I am developing a game for my thesis and im done with multiplayer and plan to start the implementation of AI but i dont know how/where to start. Please give an advice. I am developing it in C# using UNITY.
Im am now collected all pieces that has possible moves but i am stuck on which best move to select. I hope you will help me. This is link explained the game https://en.wikipedia.org/wiki/Game_of_the_Generals

# Unity Cost of multiple LUA states

This topic is 2477 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm going to use SWIG and LUA for my game's scripting system, and I ran into a design barrier. I want my script system to work like Unity3D's, how the code outside functions is where variables go, and the update, fixedupdate, awake, etc functions are called at certain times by the application. The way I could think of to do this would be to have one LUA state per game object/actor/entity, would that take up too much memory? Are there any games that actually do that? Or is there a way to do it with one global LUA state object, and call multiple functions that all have the same name, but for different objects?
Thanks for any help.

##### Share on other sites
No, you do not want to have a Lua state for each individual whatever. That's just silly. Not because of the memory usage (Lua has a small footprint, but if you have a thousand states those are going to add up), but because it doesn't make sense. I'm unfamiliar with SWIG so I can't comment on its capabilities. I use Luabind with my project and it works great.

• We have one global state
• We have hundreds of C++ functions, classes, enums, and other objects bounded to Lua
• We have functions that have the same name, but use a different signature (may be that they are either on a different class, or their parameter list/return values differ)
I think that's pretty much the way you want to go. You want to have one state so you can share data, functions, etc. across all your different script files.

##### Share on other sites
Heh, I just went back through my code and discovered that is in fact not the way we did it.

We do have multiple Lua states. It looks like we create a new Lua state for each open file, and there's also a global Lua state. I think the way it works is we bind all of our code to the global state, and each new state we create is a thread that inherits from that state or something. I honestly can't remember; Its been years since I looked through this code. Its open source though, so if you want to take a look through it and see how we did things go ahead. The code is well-commented.

Web-browsable script engine source

There's also documentation at our wiki, although I think its more intended to explain how to use the engine and not how the internals of the engine function.

Script engine documentation

##### Share on other sites

Heh, I just went back through my code and discovered that is in fact not the way we did it.

We do have multiple Lua states. It looks like we create a new Lua state for each open file, and there's also a global Lua state. I think the way it works is we bind all of our code to the global state, and each new state we create is a thread that inherits from that state or something. I honestly can't remember; Its been years since I looked through this code. Its open source though, so if you want to take a look through it and see how we did things go ahead. The code is well-commented.

Web-browsable script engine source

There's also documentation at our wiki, although I think its more intended to explain how to use the engine and not how the internals of the engine function.

Script engine documentation

A LUA state for each file would probably work. But wouldn't that add up if there were a lot of scripts? The main problem I have is that if I have an object with a script that defines the "update" function, and another one that defines a different "update" function with the same parameters. Ineed to call the right update function for the attached object. If I had a script class that managed the LUA states for each file that would work well. How much memory does a single LUA state take on average? With all the libraries loaded?

##### Share on other sites

A LUA state for each file would probably work. But wouldn't that add up if there were a lot of scripts? The main problem I have is that if I have an object with a script that defines the "update" function, and another one that defines a different "update" function with the same parameters. Ineed to call the right update function for the attached object. If I had a script class that managed the LUA states for each file that would work well. How much memory does a single LUA state take on average? With all the libraries loaded?

Of course it would add up if there were a lot of scripts. The idea is to only open the scripts that you need and close them when you no longer need them. I'd estimate we have about 10 scripts open at a time in our game currently, and I'm sure we could handle many more. If you have two update functions for the same object with the same parameters, obviously you'll have to give the functions different names (UpdateA, UpdateB) and bind both to Lua. They'd have to be different names in C++ as well, since the function signatures would be identical.

I have no idea of the memory size that a Lua state takes. That would be something that you would have to measure yourself, perhaps with a memory profiler or making a simple stand-alone application that opens a Lua state and nothing more. Unless you're developing for an embedded system (phone, handheld console) I don't think that the majority of your memory is going to be consumed by Lua though.

The key is to make your Lua files represent a large amount of related information, rather than having a ton of small files that each represent a small piece of something. For example, a single Lua file for us represents one of the following.

- Initial attributes of all characters
- Attributes for a set of 100 enemies
- A single map
- All battle actions for a type of skill (attack, defend, etc)
- All status effects
- A tileset definition file (defines the properties of tiles for a composite image that are then used to create a map)

Sometimes you just have to dive in and start getting your hands dirty before any of this makes sense. Its difficult to plan everything first and then go do it when you don't have the experience, and usually you'll find things you forgot to take into account and you have to change your plan anyway. I'd recommend you work on implementing something that is roughly what you think that you want, see how it works, then make adjustments as needed when you find you need something to be changed.

##### Share on other sites
Alright I'll just implement it. Thanks for the help.

##### Share on other sites

I'm going to use SWIG and LUA for my game's scripting system, and I ran into a design barrier. I want my script system to work like Unity3D's, how the code outside functions is where variables go, and the update, fixedupdate, awake, etc functions are called at certain times by the application. The way I could think of to do this would be to have one LUA state per game object/actor/entity, would that take up too much memory? Are there any games that actually do that? Or is there a way to do it with one global LUA state object, and call multiple functions that all have the same name, but for different objects?
Thanks for any help.

It sounds like you are after something more like this: (very roughly translated from my own code ...)

 function update_entity( entity, delta_time ) ... end function awake_entity( entity ) ... end function create_entity( stats ) local new_entity = {} new_entity.stats = stats new_entity.on_update = update_entity new_entity.on_awake = awake_entity return new_entity end function update_boss( entity, delta_time ) ... end function awake_boss( entity ) ... end function create_boss( stats ) local new_boss= create_entity( stats ) new_boss.on_update = update_boss new_boss.on_awake = awake_boss return new_boss end -- called from application function init_scene( level_description ) for i, entity_description in pairs( level_description.entities ) do ... local entity_id = ... local entity = create_entity( entity_description.stats ) entities[entity_id] = entity end ... end function update_scene( delta_time ) for i, entity in pairs( entities ) do entity.on_update( entity, delta_time ) end end function awake_entity( entity_id ) entities[entity_id].on_awake( entities[entity_id] ) end 

It is perfectly fine to organise your scripts into separate files, but I think that you should only really start using multiple lua states when you have a good reason to; ie. to run them on separate threads, to separate scripting layers, etc. Suggest also checking out http://lua-users.org...impleLuaClasses (and the rest of the wiki ) for ideas on organising your game scripts.

##### Share on other sites
Yeah, I'm seperating the scripts from each other. I want a system just like Unity's that's what I'm trying to get.