I will take you guys through a short technical overview of the process so far when creating
animated character portraits. The result, shown below, is an animated portrait of the currently selected agent which displayed in the bottom right corner.
My first idea was adding a camera to a fixed transform that moves with the character itself and rendering that to a texture. This would allow the player to see the agent in its current animation state too which seemed cool at first. After giving it a second thought it would probably not be very desirable in situations where the agent is swimming and the angle would just feel weird too if the player is swimming on a vertical plane while the camera was meant for an agent standing up etcetera.
The second idea I had, which turned out to be the idea I used for the current implementation, was making a copy from the agent and rendering that to a texture. Copying the agent has a few advantages over the previous approach. For example, the animator can be controlled independently from what the actual agent is doing in the game. Another example is the lighting, this can be adapted to the needs of a portrait instead of the scene lighting that looks quite arbitrary when displayed in a portrait.
The code.Step 1. Check if the agent has already been duplicated. If it hasn't create a copy and move it under the scene, where the lighting for the portraits has been set. If a copy already existed, simply enable it.
Step 2. Update the copy's animator to be idle so the portrait always shows an idle (or custom in the future) animation.
The setup.Step 1. Make a dedicated spot in the scene for rendering the portraits. This is done at -1000 y in our case. This is isolated enough from the rest of the game. Place your camera here and a transform that will determines the position where the generated character should pose to get some good shots.
Step 2. Have the camera for the portraits render to a texture by setting a RenderTexture in the camera settings (see gif below.)
Step 3. Display that texture on your canvas. This can be done using a Raw Image.
Step 4. Set the camera settings for the desired effect! I only wanted the agents to be drawn so I set the culling for the camera to only display that layer. I also wanted it transparant so the background from our camera setup is not drawn over the screen. Unity makes this really simple to achieve by just setting the clear flag to solid color.
All done! This is not the finished in-game version yet. This will be combined with some custom UI soon to make everything blend together nicely.
I thought you would appreciate a technical breakdown from time to time, let me know what you think!