Unity3d Support
-
- Posts: 176
- Joined: Fri Feb 27, 2009 7:12 am
- Location: Germany
- Contact:
Unity3d Support
Hi Scott,
are there any plans to implement chipmunk in Unity3D? We like to use Unity for prototyping even for 2D games. But PhysX is way more cpu demanding than chipmunk is in 2D.
Thomas
are there any plans to implement chipmunk in Unity3D? We like to use Unity for prototyping even for 2D games. But PhysX is way more cpu demanding than chipmunk is in 2D.
Thomas
Visit our game Blog: [url]http://zombiesmash.gamedrs.com[/url] or follow us on twitter: [url]http://twitter.com/zombiesmash[/url]
-
- Posts: 4
- Joined: Sun Nov 25, 2012 2:05 pm
- Contact:
Re: Unity3d Support
Just as a small note, if you have a recent NVIDIA card, PhysX is much faster than any other technique (including chipmunk), because it uses PPU acceleration 

- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Unity3d Support
I've thought about it some, but as far as I know there is no API to make a plugin provide anything like the rigid body or collision shape components that Unity provides. I'm not sure how helpful it would be without them. Also, on Unity/iOS, there is only one exposed API to call from native code back into C# and it's extremely specific and slow.
Aras from Unity twittered something about experimenting with integrating Chipmunk into Unity for a game jam back in May and how it was like ~20x faster than using PhysX. I for the life of me can't figure out how to search Twitter to find it though... What an utterly useless website.
Aras from Unity twittered something about experimenting with integrating Chipmunk into Unity for a game jam back in May and how it was like ~20x faster than using PhysX. I for the life of me can't figure out how to search Twitter to find it though... What an utterly useless website.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Unity3d Support
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 3
- Joined: Mon Mar 04, 2013 6:53 am
- Contact:
Re: Unity3d Support
I did some experiments with calling C from Mono and things look promising:
http://forum.unity3d.com/threads/172886 ... ll-C-and-C
C# to C overhead can almost be considered negligible.
When I have the time I'm going to take a look at unmanaged to managed thunks, which should be faster than UnitySendMessage. I asked Aras to chime in in Twitter, so I'm hoping for an answer before diving in.
As for the collision shapes you mentioned, it should be possible to draw them around any object via Gizmos (http://docs.unity3d.com/Documentation/S ... izmos.html).
I'll give it a try as soon as I finish my first master piece (http://facebook.com/fangz.game)
http://forum.unity3d.com/threads/172886 ... ll-C-and-C
C# to C overhead can almost be considered negligible.
When I have the time I'm going to take a look at unmanaged to managed thunks, which should be faster than UnitySendMessage. I asked Aras to chime in in Twitter, so I'm hoping for an answer before diving in.
As for the collision shapes you mentioned, it should be possible to draw them around any object via Gizmos (http://docs.unity3d.com/Documentation/S ... izmos.html).
I'll give it a try as soon as I finish my first master piece (http://facebook.com/fangz.game)

- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Unity3d Support
So it's been a couple months since I looked at it last, so I might be wrong. IIRC Mono had 2 ways to call from C back into C#, one of them was dynamic-ish and used trampoline functions (which are not allowed on iOS due to memprotect() restrictions). The other way required using Mono APIs where you would need to get C# object references, and method references in order to invoke them. It's a bit fuzzy, but I remember thinking that it wasn't made possible to do somehow.
Calling from C# out to C is easy enough, but anything that uses a callback heavy API (like many parts of Chipmunk) were made quite difficult.
Again, the other big part is that the way that Unity's rigid bodies interact with transforms automagically seems to be using private APIs. I couldn't find anwhere in the docs how you could interact with the game loop or transforms from native code.
I'd love to be proven wrong though. :-\ I think Chipmunk would make Unity a much better tool for 2D games.
Calling from C# out to C is easy enough, but anything that uses a callback heavy API (like many parts of Chipmunk) were made quite difficult.
Again, the other big part is that the way that Unity's rigid bodies interact with transforms automagically seems to be using private APIs. I couldn't find anwhere in the docs how you could interact with the game loop or transforms from native code.
I'd love to be proven wrong though. :-\ I think Chipmunk would make Unity a much better tool for 2D games.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 3
- Joined: Mon Mar 04, 2013 6:53 am
- Contact:
Re: Unity3d Support
I'll start investigating the C to C# part in a couple of weeks. The reference method you're mentioning is probably unthunked to thunk mentioned here: http://www.mono-project.com/Embedding_Monoslembcke wrote:The other way required using Mono APIs where you would need to get C# object references, and method references in order to invoke them. It's a bit fuzzy, but I remember thinking that it wasn't made possible to do somehow.
Again, the other big part is that the way that Unity's rigid bodies interact with transforms automagically seems to be using private APIs. I couldn't find anwhere in the docs how you could interact with the game loop or transforms from native code.
As for the rigid bodies, there's really nothing that forces you to use them (and you wouldn't be able to extend them, because Unity made RigidBody a sealed class...). They're just a component made to interface with PhysX (almost all of the RigidBody API is a simple wrapper). In my approach I would simply make another component called ChipBody

The editor part of RigidBody is also pretty standard, so I think it would be relatively easy to have a ChipBody.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Unity3d Support
What I mean though is that once you add that ChipBody component, you need to either write C# code in a fixed update method somewhere that copies the Chipmunk transform to Unity. The built in rigid bodies do this automagically before (or after? I forget) any fixed update methods are called so that there aren't any component call ordering issues.
Having little on no control over the order that components are executed in is the bane of your existence in component based engines IMO. It's caused so many frustrating bugs and awkward workarounds in our Unity projects. :-\
Having little on no control over the order that components are executed in is the bane of your existence in component based engines IMO. It's caused so many frustrating bugs and awkward workarounds in our Unity projects. :-\
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 3
- Joined: Mon Mar 04, 2013 6:53 am
- Contact:
Re: Unity3d Support
A simple copying in FixedUpdate should do the trick. I just downloaded a Unity plugin that does most of what I want to do, but for Box2d. I took a look at the code and they're copying the position in the FixedUpdate.
They've also managed to avoid using UnitySendMessage by creating a function to setup a callback.
The plugin is NativeBox2d if you want to check it out.
They've also managed to avoid using UnitySendMessage by creating a function to setup a callback.
The plugin is NativeBox2d if you want to check it out.
Who is online
Users browsing this forum: No registered users and 11 guests