Report article RSS Feed CATIA, Unity and COM

Posted by Herr_Alien on Apr 26th, 2010

If you already programmed in COM, feel free to skip the article. Yep. Nothing interesting for you here.

If you're a coder that has some experience with previous game engines but you're new to Unity, then read on.

So. Two programs and a technology for software development. And a picture:COM object and interfaces

That's a COM object. Our target is "Outer Object". It imlements several interfaces, the circles labeled A, B ...

In terms of inheritance, you could do that by deriving the class describing. Now of course, there are some problems when all them interface implement a function with the same signature, say void Update(): which Update() should be called in your case? The one from A? Or B? Or C? I personally don't like C, as a vitamin at least it is sour.

This is where COM ... comes in place. In COM, if you want to implement an interface on an object, you'll get a new instance of a class. That means that somehow, in your objects, you'll have at least three class instances, one that implements the functionality of A, one for B, well, you get the point.

Why the frowned face? Oh, stupid me, I forgot something: from now on, your object is no longer an instance of one class. No. That's gone. Think of it as a collection of classes, each working together to provide functionality for one object.

Now I can hear you saying: "But what if I need to use functionality from Interface A in the implementation of Interface B? How can I reach one functionality from the other?"

In all technologies that implement an object modeling mechanism (yep, that's the OM from COM), there will always be a mechanism to go from one interface to the other. In COM, it is called "QueryInterface". In Unity, you  GetComponent.

Now it makes sense. This is why the First Person Controller prefab in Unity looks like this:

Unity's fps controller 



You'll see that I underlined two components (get used to the term if you plan to use Unity). If you double click them, you'll end up looking at some C# code. Each of the scripts describe a class, each having a Start() and Update() function. Several components, working to define one object.
And here's another thing about COM: you can re-use components:

camera



The Mouse Look script is the shared component here.

That's it. Don't say I didn't warn you, if you know COM this was not a surprise.

Post comment Comments
dreamtail
dreamtail Jan 3 2011, 2:20am says:

Hey Herr I made an account I'm now much wiser so I'm not a complete moron

+1 vote     reply to comment
Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Level
Avatar
Avatar
Offline Since
Sep 15, 2014
Country
Romania Romania
Gender
Male
Member Watch
Track this member
Blog
Browse
Blogs
Report Abuse
Report article