Hero Agents for Raytracing/Morph Targets

Usually all the agents are drawn using a single "Skeletal Instanced Component" using the instancing capability of your GPU. This component can handle many agents using few gpu resources and power. At the moment this component has some limitations. It's not visible by raytracing and doesn't support morph targets. If you want to use these unreal features you need an hero agent. An Hero agent is a agent that is using a single "Posable Bounded Mesh Component". This component inherits from the Skinning Mesh component so it can be used with raytracing or morph targets. Every hero agent uses its own posable component. So if you promote 10 agents to hero agents the agent group adds at least 10 posable mesh component. You can promote to hero any agent you want dynamically during the simulation and you can revert back to a normal agent any hero you want dynamically as well. 


Promote all agents

To promote all agents to hero in a group you need turn on the PromoteAllAgentToHero property on the AtomsAgentGroup actor.

  • Create and AtomsAgentGroup actor

  • Add a Grid layout behaviour component and set as agent type property one of the agent type you have in your project. Then change the size property to 5,5,1 to create a grid of agents.

  • Add a state machine or clip reader behaviour module to add some animation to the agents.

  • On the agent group actor activate the PromoteAllAgentToHero property.

If you now check the actor components attached to the actor you will see a “Posable Bounded Mesh Component” for each agent.

Promote agents by groupId

You can promote specific agent using their groupId.

  • Create and AtomsAgentGroup actor

  • Add a Grid layout behaviour component and set as agent type property one of the agent type you have in your project. Then change the size property to 5,5,1 to create a grid of agents.

  • Add a state machine or clip reader behaviour module to add some animation to the agents.

  • On the agent group actor add to the “Agent Heroes” map the id 1,2,5,8.

If you now check the actor components attached to the actor you will see a “Posable Bounded Mesh Component” for the agent 1,2,5 and 8.

 

Promote agents by metadata

You can promote agents and also convert back an hero to an normal agent using a custom metadata on the agents.

  • Create and AtomsAgentGroup actor

  • Add a Grid layout behaviour component and set as agent type property one of the agent type you have in your project. The change the size property to 5,5,1 to create a grid of agents.

  • Add a state machine or clip reader behaviour module to add some animation to the agents.

  • Add a “Add metadata behaviour component“, set the name property to “myHero“ and the type to bool. Set the bool value to true.

  • On the agent group actor set the “Promote Agent Hero Metadata” to “myHero“.

Now all the agents are promoted to hero. Since the agent group uses the metadata to promote the agents you can override the “myHero” metadata using the override dialog on the add metadata behaviour.

Promote agents by distance form the player

Since we can control the hero agents using a metadata you can promote or revert an agent dynamically during the simulation. For instance, you can promote agents that are a specific distance from the camera using the “frustum trigger behaviour component”.

  • Create and AtomsAgentGroup actor

  • Add a Grid layout behaviour component and set as agent type property one of the agent type you have in your project. The change the size property to 5,5,1 to create a grid of agents.

  • Add a state machine or clip reader behaviour module to add some animation to the agents.

  • Add a “Add metadata behaviour component“, set the name property to “myHero“ and the type to bool. Set the bool value to false and the “Agent Creation only“ property to true.

  • On the agent group actor set the “Promote Agent Hero Metadata” to “myHero“.

  • Add a frustum trigger behaviour component. Set the metadata name property to “myHero”, the “Keep Value“ field to false, the “far plane“ to 500 and the “bool value“ property to true.

The frustum trigger works like the area trigger behaviour component, but uses the camera frustum as input instead of a mesh. So it sets a metadata on the agents that are inside the frustum and with a distance included between the near and far plane property. So in this case it’s promoting all the agents that are inside a distance of 500 units from the player. Play the level and pause the sim at a different times, check the posable mesh component active to see which agents are promoted to heroes.

 

Using per instance metadata on materials used by hero agents

If you are going to use per instance metadata to send metadata to your agent materials you need to setup those materials to be able to use them also on hero agents. Usually the metadata are transferred to the materials using the “Particle Color” and the “Dynamic Property“ material nodes. If you try to use a material with these nodes on a hero agent you will see everything black since the posable mesh component is not able to fill the data to these nodes. In order to make it works you need to use a parameter material node.

  • Follow the previous paragraph to setup an agent group with the frustum trigger behaviour component.

  • Add an “Add metadata behaviour“ component to the agent group. Set the name property to “myColor“, the type to “vector“ and the vector3 value to 1,0,0 and the “Agent Creation only“ property to true.

  • On the agent group actor add “myColor” to the “Per Instance Metadata” property and the “Update Per Instace Metadata at Every Tick“ to true.

  • Open one of the materials that your agent is using. Create a Particle Color node and connect it’s output to the input color of your material.

If you run the level now you will see that the hero agents are using a wrong color on your material.

  • Open the material again.

  • Create an ScalaParameter node and set its name to “Hero“.

  • Create a VectorParameter node and set its name to myColor.

  • Create a LInearInterpolator node and connect the particle color to A the VectorParameter to B and the ScalarParameter to Alpha.

  • Connect the output of the interpolator node the the material color input.

  • Save the material.

If you run the level now also the hero agents are using the right material color. When an agent is promoted the agent group pass to the “Hero“ material node a value of 1 and the search for a parameter node with the same name of the metadata to pass the metadata value. With the linear interpolator node the material now can handle the hero agents and normal agents as well.

 

Enable Raytracing

You can enable raytracing on the hero agents. You just need to turn on the “Visible In Raytracing“ property on the agent group actor. This property is then passed to each posable mesh component and you hero agents will be visible to the raytracing pass.

 

Morph Targets

Hero Agents support morph targets. To activate a morph target on an agent you need to add on the agent a double metadata called:

agent_type_name + _ + morph_target_name

For example if you have the agent type “man” and one of the skeletal mesh has a “eyeBlink” morph target you can add a double metadata in blue print or use the “add metadata beheviour“ component providing man_eyeBlink as name.

 

If you want to drive a morph target using a clip you can add a curve on the anim sequence and use the morph target name as curve name. During the simulation this curve is translated to a metadata and saved on the root joint metadata of the agent that is using that clip. The agent group checks this metadata and sends the weight to the posable mesh component.

 


Tutorial

 

Copyright © 2017, Toolchefs LTD.