Has anyone pulled Unity into an Xcode project?

So I know that pulling xcode into Unity is rather simple. Unity can just call any C function included in your Xcode project, and that can spawn whatever you want it to.

However, I am looking to pull Unity into an already existing XCode project to use as essentially a rendering module when necessary. Has anyone done this? Any insight you could offer?

thats not possible in any reasonable way

you can’t call into the engine at all, its no sdk but a self contained system that allows you to expand it with external functionality (call c functions as you call it) but not the other way round.

Why not?

If unity is a EAGLView, shouldn’t you be able to edit to load and unload that EAGLView on demand?

You could do it if you pass data to unity constantly, with xcode controlling the logic, see docs under plugins - but its a really horrid way to do things :stuck_out_tongue:

I wouldnt need to constantly pass data. The use of this will be more along the lines of, you have the main app coded in objective C, then you click something and it will load a 3D interactive segment in unity, you run through that, then it closes the unity portion and goes back to xcode. You can already do this with NativeUIToolkit. The thing that I am wanting to get around is the need to always have unity loaded in memory. I would like to put off the loading of the 11 mb of memory overhead for unity until its necessary, and then perhaps even free up that 11 mb…

Is it possible to get unity to take up less than 11 mb?

10 maybe if it’s empty. Not really :stuck_out_tongue:

You can’t save memory if you include unity or unload it, because unity is compiled with the xcode source for the final executable…

You can modify the eaglview, thats no problem. But thats the only thing you can do. The rest is within a static library out of any access for ya.

Question is what you really want to do. Control when it goes up and down and is paused? then its trivial.

But if you want to use it as rendering sdk within another application, you will not be happy. Using Oolong, Irrlicht or OGRE is a better approach there.

Also the ‘always loaded in ram’ for the engine itself is unavoidable, the code is loaded into RAM anyway. the only thing you could impact is if the assets are in there by killing the engine … but unity wasn’t designed to be used like this, I am not sure how well it works or if you can even start it up a second time / if shutting it down the first time won’t take down the whole app

No I do not want to use it as a rendering SDK.

I want to use it more like a self contained interactive component that can be called up when necessary, and become fullscreen, completely covering up any xcode functionality. More along the lines of a video player, except a 3D scene player.

This is very well possible. The thing is just, that Unity uses so many ressources, that you will have a noticible Delay of like 1 - 3 Sekonds even on ipad 2 while you load it - even if you use stripping and and empty start scene.
But once you succeded you can put other UIViews on top, thus make a complete GUI in interfacebuilder or so. As long as you don´t send Informations on a per frame base between objective C and Unity you are fine.

What i could NOT do so far is to remove unity completly within the app running. So, i pause it when switching to other content and load and empty scene to save memory.

Still this a approach is by far not hassle free and you should follow dreamoramas advvice and look for pure Objective C Open GL ES frameworks. You might want to google for nineveh gl and iSGL3D.
Use that if you need something relativly basic like a 3D model Viewer. On the other hand, if you need a lot of features unity has, like collisions, Animations, gamelogic, physix and so on, then stick with unity.

The advanced functionality of Unity is halfway required for this project, I am on the edge about leaving Unity for this project.

I could get away without Physx, the project doesn’t really need it, I was going to use it for some added ‘graphical fluff’ on the 3D portions, but I could do without physics.

Animations, the ability to have rigged meshes is something I’d like to keep available. This is for an archviz project, I was hoping to potentially take advantage of unity’s upcoming crowd simulation to have people walking around spaces. But that is also fluff and not really necessary.

Gamelogic is used pretty extensively. These enviroments are highly interactive, opening closing doors, rearranging of furniture, tweens all over the place, being able to rearrange models, reposition models, or contents of models. Assetbundles will be used extensively, and pulling content for the web.

Was hoping to take advantage of light probes in these scenes when 3.5 comes… Also wanted to take advantage of LOD and upcoming texture streaming. Those three things are actually very crucial for this project.

Really the thing that makes me so hesitant to leave Unity is the editor. What I am doing is something that requires a tool to set up scenes. Theres alot more information that needs to be in these scenes besides just vertices and textures. And I worry that if I go to something else I am going to have to invest alot of time to produce my own scene editing tools to set the scenes up properly.

I also worry about the dev time required to replicate even just innane tasks in Unity, like the projection shader.

These scenes are also going to be pushing the borderline of what the iPad2 can handle graphically, and I worry that other engines don’t have the level of optimization of Unity, and further than that, they won’t be able to keep up with the rate that Unity optimizes their engine. Performance is critical.

So I guess with all that said, I would like to know, is there any other options for a 3D engine that has, ideally, better performance than Unity. And perhaps has some level editing tools? If it comes with any form of texture or content streaming, thatd be very useful. I’ve been looking at all these open source options and some of them actually look really nice, but they appear to have no good editing tools that come with them. Just getting a 3D rendering class to import into Xcode, without any functioning tools to aid the creation of the content, will probably mean a considerable increase in workload for me to create usable tools to go along with the rendering engine.

This is for an enterprise application, and the thing about this specific project is, I can enforce hardware requirements, and say that an iPad 2 or iphone 4s is required. Then further, upgrade that to the iPad 3 as a minimum when thats released. So keeping the 11 mb in memory does not worry me too much, because an iPad 2 will be minimum. This company also I think would prefer a slightly dirtier solution internally, if it means they get a product even just a few months earlier… This is also a component of why I am leaning towards pushing Unity into this somewhat less than ideal usage.

On a sidenote. I’ve got it set up so that I can call the ‘StartUnity’ function from my ObjectiveC app and have it load Unity and its required memory usage on command.

Having some trouble figuring out how to unload it…

Has anyone ever dealt with the ‘UnityCleanup’ function in the objective c of a built unity project? After much studying I have narrowed it down to this single function probably being the one that will unallocate the chunk of memory unity takes up, but any form or way or order of other commands I call UnityCleanup in, it crashes.

Has anyone successfully called UnityCleanup() in their own function?

So thought I should write back here, in case anyone searches in the future.

I successfully got Unity into a subview that can be animated to slide on top of and off of an already existing xcode project. Works just fine.

However you cannot unload unity from memory once already loaded, unless your like a master hacker that can deal with assembly code and indirect alteration of memory. The functions necessary to unload Unity at runtime just really don’t exist…

Hi, i’m very interested in your work. I need to put Unity on an subview and use it as viewer. The controller for the viewer is a native application in Objective-C.
The native GUI has to be an overlay layer on top of the Unity viewer.
Could you give me some tips to do that?

Hello,

Does everyone know how to load Unity into a subview like techmage have done ? It would be very usefull for me…

Thanks
Ohms