# AI optimization

**URL:** <https://forums.unrealengine.com/t/ai-optimization/352549>\
**Category:** AI\
**Tags:** ai-navigation, Behavior-Tree, unreal-engine, question\
**Created:** [April 1, 2016, 9:13pm UTC](https://forums.unrealengine.com/t/ai-optimization/352549 "2016-04-01T21:13:03Z")\
**Posts on this page:** 1\
**Showing post:** 19

<div class="post-metadata">

**Author:** ![Anonymous\_e5d5c0bf7d300728867097ff79906dbe](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anonymous\_e5d5c0bf7d300728867097ff79906dbe](https://forums.unrealengine.com/u/Anonymous_e5d5c0bf7d300728867097ff79906dbe)\
**Post date:** [September 11, 2017, 2:18pm UTC](https://forums.unrealengine.com/t/ai-optimization/352549/19 "2017-09-11T14:18:29Z")

</div>

Ok, so here you go:

You have to create your own CharacterMovementComponent:  
And add to it’s header:

```
UCLASS()
class YOUR_GAME_NAME_API UCM: public UCharacterMovementComponent
{
	GENERATED_BODY()

protected:
	//Init
	virtual void InitializeComponent() override;

public:

        //Useful to make sure that your characters are using the correct Component.
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = StubCheck)
	bool m_dummyToMakeSure; 

	virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;

private:
	float m_DeltaTime;
	int m_nTicksCount;
	int	m_nTickGroup;

	bool m_SkipFloorChecks;
};

```

In the CPP

```
void UCM::InitializeComponent()
{
	Super::InitializeComponent();

	m_nTickGroup = FMath::RandRange(3, 4);
	m_DeltaTime = 0.0f;
	m_SkipFloorChecks = FMath::RandBool();
	m_nTicksCount = 0;
}

void UCM::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
   	m_DeltaTime += DeltaTime;
	if (!CharacterOwner->GetMesh()->bRecentlyRendered)
	{
		if (++ m_nTicksCount % m_nTickGroup == 0)
		{
			m_nTicksCount = 0;
			DeltaTime = m_DeltaTime;
		}
		else
		{
			return;
		}
		
	}

	m_DeltaTime = 0.0f;

	//Call Default CharacterMovementComponent
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}

```

This code snippet will cull of some of the Movement Component overhead for an invisible Characters.  
Theoretically it should increase the number of Characters (that are off-screen) twice.

Please refer to this Wiki Page: on how to create a custom CharacterMovementComponent

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

---

_[View the full topic](https://forums.unrealengine.com/t/ai-optimization/352549)._
