Importing 'prefabs' objects in a scene

176 views
Skip to first unread message

Mike

unread,
Dec 22, 2013, 1:52:33 AM12/22/13
to urh...@googlegroups.com
I'm trying to import a 'prefab' xml object in a scene using lua scripting.

From the ninja snow war example, it seems that this is achieved using the InstantiateXML function from angelscript API, but I haven't found an equivalent function in the lua API.

Lasse Öörni

unread,
Dec 22, 2013, 2:01:29 PM12/22/13
to urh...@googlegroups.com
You'll find that the Lua API is not 100%, typically "difficult" things that have to do with file access or object allocation via shared pointers are not all there.

I added Instantiate & InstantiateXML in a recent commit. There's an example in the commit message.

Mike

unread,
Dec 23, 2013, 6:59:43 AM12/23/13
to urh...@googlegroups.com
Awesome! Works perfectly.

Mike

unread,
Dec 23, 2013, 8:48:49 AM12/23/13
to urh...@googlegroups.com
Now I have trouble getting the physics from the prefab to work.

Lasse Öörni

unread,
Dec 23, 2013, 1:57:49 PM12/23/13
to urh...@googlegroups.com
Do you have a PhysicsWorld component in your scene root node? I didn't have trouble making eg. the ninja prefab behave physically when I instantiated it into the Physics Lua sample scene.

Mike

unread,
Dec 23, 2013, 4:42:03 PM12/23/13
to urh...@googlegroups.com
Sorry for this one, I forgot to update my resource path in the editor, now everything works as expected.

Mike

unread,
Dec 30, 2013, 4:44:33 PM12/30/13
to urh...@googlegroups.com
Just tested on Android (with luaJIT enabled). Unfortunately it doesn't work for now.

Chris Friesen

unread,
Dec 30, 2013, 4:54:47 PM12/30/13
to urh...@googlegroups.com
If you changed the resource paths via command line execution you will have to add them to CommandLine.txt

Chris Friesen

unread,
Dec 30, 2013, 4:56:29 PM12/30/13
to urh...@googlegroups.com
IOS & Android read from that file since you can't read program arguments.

Mike

unread,
Dec 31, 2013, 1:42:49 AM12/31/13
to urh...@googlegroups.com
Thanks for tips Chris.

I'm already using default resource path for the assets to instantiate.
I think the issue comes from using fileSystem:GetProgramDir() instead of cache:GetResource.
I've tried to use
cache:GetResource previously but it failed (tested on desktop).

Lasse Öörni

unread,
Dec 31, 2013, 7:03:36 AM12/31/13
to urh...@googlegroups.com
On Android & iOS there's a slight hack for accessing the resources bundled with the application, and it doesn't make sense to try to add extra resource directories. On these systems FileSystem::GetProgramDir() returns the directory for accessing them. Normally the CoreData & Data directories would be copied as resources.

Mike

unread,
Dec 31, 2013, 8:53:13 AM12/31/13
to urh...@googlegroups.com
So is it possible in some way to use resources cache instead of Filesystem to access the objects with the InstantiateXML function?

Lasse Öörni

unread,
Dec 31, 2013, 10:30:29 AM12/31/13
to
In C++ and AngelScript certainly, as you can call ResourceCache::GetFile() which does the lookup for you and returns a file. In Lua this likely isn't possible currently.

However note that there's nothing magical in what ResourceCache is doing; opening a file with a path constructed like GetProgramDir() + "Data/YourResourceName" should access files just fine on iOS and Android too. The "magic" to access resources from within an apk is in the File class.

Mike

unread,
Dec 31, 2013, 11:42:22 AM12/31/13
to urh...@googlegroups.com
OK, thanks, will try to figure out what's going on.

Reply all
Reply to author
Forward
0 new messages