Runtime Variations

Instead of creating the variations asset like explained here, you can create variations at runtime. The agent type component lets you attach a new skeletal/attachment mesh instanced component at runtime. Then you can add/remove an agent to the draw list of a specific skeletal/attachment mesh instanced component.

  • Create an agent group actor.

  • Add a grid layout component. Set a valid agent type, then set the size property to 5, 5, 0.

  • Add a state machine or clip reader component.

 

  • Select the agent group actor and then open the blueprint level editor.

  • Create the OnAgentsCreatedEvent node.

  • Create a “GetComponentByClass” and get the agent type component. This node returns the agent type component “man“ that the agents are using. IF you have multiple agent type components, you need to get the right one for your agents.

 

  • Add an AddSkeletalMeshInstancedComponent node and set the skeletal mesh you want to use. If a skeletal mesh component using the same skeletal mesh asset already exists, this node doesn’t add a new component but returns the existing one.

 

  • Use a for loop to iterate over each agent.

  • Use the “AdddAgentToSkeletalMeshInstanced“ method of the agent type component to add the agent to the draw list of the skeletal mesh instanced component.

 

If you want to remove an agent from the draw list of a skeletal mesh instanced component, the agent type component has a RemoveAgentFromSkeletalMeshInstanced method. You can also use the RemoveAgent or RemoveAgents to remove an agent from the skeletal mesh instanced components draw list.

Copyright © 2017, Toolchefs LTD.