I'm currently doing some research on programming languages(compile time reflection area, if you ask) and I found that on the game engine area the reflection feature becomes a must, an engine either uses a language which has reflection feature itself(for example uses C#), or implements it for non-reflection languages(for example both UE and CryEngine implement reflection mechanisms for C++).

I'm not a game developer, so I have no experiences on game developing and not familiar with engines, so can anyone tell me in what case the reflection becomes a must? And what's more, does reflection used only in development phase or also used in released production?

  • 19
    \$\begingroup\$ I tried to find how CryEngine uses code reflection, however I only saw results about ray tracing. By the way, when I first saw your question, I thought it was going to be about physically based rendering. \$\endgroup\$ – Theraot Jan 19 '20 at 7:12
  • \$\begingroup\$ @Theraot not really, indeed I don't know what physically based rendering is, I just want to know a common usage of reflection. \$\endgroup\$ – ravenisadesk Jan 19 '20 at 7:30
  • 10
    \$\begingroup\$ If you want a common usage of code reflection, regardless if it is in game development or not, see testing frameworks and how they work. Usually reflection used to discover the test cases to run. I had an initial confusion because when talking about game engines the first thing that comes to my mind when mentioning "reflection" is making in-game surfaces reflective (for example to make them look metallic, or making mirrors in-game). \$\endgroup\$ – Theraot Jan 19 '20 at 7:40
  • \$\begingroup\$ @Theraot yeah, that is, that's why I add 'code-reflection' label. As you said the test framework, let's say a test framework for C++ project, it may use reflection, but it used on its own, that is, a programmer which writes the project neither cares the implementation nor can use the reflection mechanism. I asked because I get a feeling that in game area, no matter the reflection is used or not, it exists, that's why I practically mentioned if the reflection is used in released production. \$\endgroup\$ – ravenisadesk Jan 19 '20 at 7:53
  • 4
    \$\begingroup\$ After release, mods would be where reflection is used more heavily. In particular mods that are deployed as binaries (not script or config files). Either the game has support for mods and uses reflection to get an interface to call inside the mod... or the mod uses reflection to hook into the game (sometimes a form of injection is used to install the mod). \$\endgroup\$ – Theraot Jan 19 '20 at 7:59

It allows to expose variables and functions to be used in the editor. That is, the game creation tool will use a form of reflection (or similar) on the code provided by the developers, which then allows it to expose parts of it in editors for designers.

For example, let us say a developer has created a class of objects (created as source code) to be placed in game by the level designers. However, there are some properties the developer wants to allow the designer to tweak. To do this, the tool will have to expose these properties to the level designer in the editor.

Similarly, functions/methods could be exposed. Which may allow to use them in scripting (including visual scripting, for example “blueprints”) or even allow to call them from an in-game debug console.

Since the editor cannot know the type information before hand (the editor was created before the game). Instead the editor will need a manifest with this information. To get this manifest, the editor (uses a tool that) generates it, either directly from the source (this could be part of the built process) or from a binary. The developer might have to mark what to expose.

This is similar to how Visual Studio form designer shows you a property panel where you can edit the properties of the controls you place... and that the controls had been built beforehand.

See also Unreal Property System (Reflection).

We might also find reflection and emission to generate bindings for different languages. That is, the engine has main supported language, yet the developers of the engine want to provide the ability to write code for the engine in other languages... if they are not integrating a compiler for those languages, then they need an SDK for those languages. Well, they can generate code for those languages by doing reflection on their API and emitting the SDK interop code. Add this to continuous integration, and this ensures that the SDK code is always up to date.

Yet another place where we might find reflection is when loading plugins or mods.

  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$ – Vaillancourt Jan 20 '20 at 16:20
  • 3
    \$\begingroup\$ Object serialization (e.g. for saving/loading, or for sending messages to a game server) is another classic example. \$\endgroup\$ – 0x5453 Jan 21 '20 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.