# Wiki Code Tutorials

**URL:** <https://forums.unrealengine.com/t/wiki-code-tutorials/256>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [March 20, 2014, 9:39pm UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256 "2014-03-20T21:39:34Z")\
**Posts on this page:** 20\
**Page:** 11

<div class="post-metadata">

**Author:** ![Jambax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jambax/32/904177_2.png) [@Jambax](https://forums.unrealengine.com/u/Jambax)\
**Post date:** [January 16, 2015, 11:04am UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/217 "2015-01-16T11:04:11Z")

</div>

Hey guys, I also posted a quick tutorial (using’s examples as a template, hope that’s okay!)

**How to access the functions and variables of an object specified in a \<TSubclassOf\> container.**  
[https://wiki.unrealengine](https://wiki.unrealengine)./Access\_Functions\_%26\_Variables\_From\_a\_TSubclassOf\_Variable\_in\_C%2B%2B

Thanks!

---

<div class="post-metadata">

**Author:** ![DennisSoemers](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DennisSoemers](https://forums.unrealengine.com/u/DennisSoemers)\
**Post date:** [January 17, 2015, 12:39pm UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/218 "2015-01-17T12:39:56Z")

</div>

Hey, I have a comment on page: [https://wiki.unrealengine](https://wiki.unrealengine)./Templates\_in\_C%2B%2B

You mention that, because templates require definitions of the methods in the .h files anyway, the FORCEINLINE keyword should be used. I don’t really agree with that as a rule of thumb. Inlining functions increases the size of the code. Sometimes, people may not care about the size of the code and only the number of CPU cycles it takes to run, and then I agree that FORCEINLINE would often result in a performance increase… but even that is not always true. The increased code size can have a negative impact on your performance, even taking into account that the function call overhead is avoided (see Sections 3.4 and 6.2.2 of [http://www.akkadia.org/drepper/cpumemory.pdf](http://www.akkadia.org/drepper/cpumemory.pdf)).

I would strongly recommend not to use FORCEINLINE at all, unless extensive profiling indicates that it does result in better performance in a highly performance-critical area of the game’s code. In general, it is fairly safe to rely on the compiler to make the right decisions with respect to whether or not code should be inlined (it can still do so even if you don’t use the FORCEINLINE or inline keywords).

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [January 20, 2015, 9:57pm UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/219 "2015-01-20T21:57:26Z")

</div>

[=DennisSoemers;206995]

I would strongly recommend not to use FORCEINLINE at all, unless extensive profiling indicates that it does result in better performance in a highly performance-critical area of the game’s code. In general, it is fairly safe to rely on the compiler to make the right decisions with respect to whether or not code should be inlined (it can still do so even if you don’t use the FORCEINLINE or inline keywords).  
[/]

Hi there Dennis! Great to hear from you!

I’ve modified the wiki to mention that you should probably just let the compiler figure it out if your function body is large!

I am presuming that readers of my wiki will actually look up “C++ inline function” and read about all these details, including your concerns about code bloat.

I can’t explain everything in my wiki pages 🙂

In case you’re wondering, I am assuming that readers of my wiki understand that C++ is one of the most well-documented languages on the planet, and they can find out more information about any topic by searching for themselves 🙂

But thanks again for your input, I’ve modified my phrasing on the wiki to make it more clear that user discretion is required when using FORCEINLINE!

Have fun today!

❤

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [January 23, 2015, 6:00am UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/220 "2015-01-23T06:00:50Z")

</div>

Dear Community,

I’ve just posted a new wiki!

I am giving you easy-to-use pre-processor commands to get a UE4 String that tells you the Class Name, Function Name, and Line Number of the calling code!

**Logs, Printing the Class Name, Function Name, and Line Number of your Calling Code!**  
[https://wiki.unrealengine](https://wiki.unrealengine)./Logs,\_Printing\_the\_Class\_Name,\_Function\_Name,\_Line\_Number\_of\_your\_Calling\_Code!#My\_C.2B.2B\_Code\_For\_You

````auto

**Pics**

![a51b4eb12a773cd47ef504c3015401ed5a1222f7.jpeg|1280x960](upload://nyBhSL7AeJYRaiuAA8hU6eu26hN.jpeg)

After you get my .h file below, the code for the above picture is !

```

// ~~~Tick~~~
void AEVCoreDefense::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	// ~~~~~~~~~~~~~

	VSCREENMSG("Got Here!"); //Class and line number get printed for you! ♥ 
}

```

![76592038c1a622532653d3516d343bb88787467e.jpeg|1280x960](upload://gSXi9wvKFnU8eJKryUDfNDEi8eG.jpeg)

````

**Code**

**Here is the entire file you can #include in your code base!**

I made a file called JoyCurrentClassFuncLine.h

So you would then do somewhere at the top of one of your core classes:

```auto

// Joy Class Func Line
**#include "JoyCurrentClassFuncLine.h"**

```

```auto

**/*
	Joy String 
		Current Class, File, and Line Number!
			by
			
	PreProcessor commands to get 
		a. Class name
		b. Function Name
		c. Line number 
		d. Function Signature (including parameters)
		
	Gives you a UE4 FString anywhere in your code that these macros are used!
	
	Ex: 
		You can use JOYSTR_CUR_CLASS anywhere to get a UE4 FString back telling you 
		what the current class is where you called macro!
	
	Ex:
		macro prints the class and line along with the message of your choosing!
		VSCREENMSG("Have fun today!");
	<3 
*/**
#pragma once

**//Current Class Name + Function Name where is called!**
#define JOYSTR_CUR_CLASS_FUNC (FString( __FUNCTION__ ))

**//Current Class where is called!**
#define JOYSTR_CUR_CLASS (FString( __FUNCTION__ ).Left(FString( __FUNCTION__ ).Find(TEXT(":"))) )

**//Current Function Name where is called!**
#define JOYSTR_CUR_FUNC (FString( __FUNCTION__ ).Right(FString( __FUNCTION__ ).Len() - FString( __FUNCTION__ ).Find(TEXT("::")) - 2 ))
  
**//Current Line Number in the code where is called!**
#define JOYSTR_CUR_LINE (FString::FromInt( __LINE__ ))

**//Current Class and Line Number where is called!**
#define JOYSTR_CUR_CLASS_LINE (JOYSTR_CUR_CLASS + "(" + JOYSTR_CUR_LINE + ")")
  
**//Current Function Signature where is called!**
#define JOYSTR_CUR_FUNCSIG (FString( __FUNCSIG__ ))

**//Victory Screen Message
// Gives you the Class name and exact line number where you print a message to yourself!**
#define VSCREENMSG(Param1) (GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, *(JOYSTR_CUR_CLASS_LINE + ": " + Param1)) )

```

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [January 30, 2015, 10:21am UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/221 "2015-01-30T10:21:56Z")

</div>

**New Debugging PreProcessor Commands**

I added some additional pre-processor commands to my wiki above!

UE\_LOG and additional Screen Msg commands, that all tell you where you are in your code base automatically, including the line number!

```auto

// Joy Class Func Line
**#include "JoyCurrentClassFuncLine.h"**

```

```auto

**/*
	Joy String 
		Current Class, File, and Line Number!
			by
			
	PreProcessor commands to get 
		a. Class name
		b. Function Name
		c. Line number 
		d. Function Signature (including parameters)
		
	Gives you a UE4 FString anywhere in your code that these macros are used!
	
	Ex: 
		You can use JOYSTR_CUR_CLASS anywhere to get a UE4 FString back telling you 
		what the current class is where you called macro!
	
	Ex:
		macro prints the class and line along with the message of your choosing!
		VSCREENMSG("Have fun today!");
	<3 
*/**
#pragma once

**//Current Class Name + Function Name where is called!**
#define JOYSTR_CUR_CLASS_FUNC (FString( __FUNCTION__ ))

**//Current Class where is called!**
#define JOYSTR_CUR_CLASS (FString( __FUNCTION__ ).Left(FString( __FUNCTION__ ).Find(TEXT(":"))) )

**//Current Function Name where is called!**
#define JOYSTR_CUR_FUNC (FString( __FUNCTION__ ).Right(FString( __FUNCTION__ ).Len() - FString( __FUNCTION__ ).Find(TEXT("::")) - 2 ))
  
**//Current Line Number in the code where is called!**
#define JOYSTR_CUR_LINE (FString::FromInt( __LINE__ ))

**//Current Class and Line Number where is called!**
#define JOYSTR_CUR_CLASS_LINE (JOYSTR_CUR_CLASS + "(" + JOYSTR_CUR_LINE + ")")
  
**//Current Function Signature where is called!**
#define JOYSTR_CUR_FUNCSIG (FString( __FUNCSIG__ ))

**//Victory Screen Message
// Gives you the Class name and exact line number where you print a message to yourself!**
#define VSCREENMSG(Param1) (GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, *(JOYSTR_CUR_CLASS_LINE + ": " + Param1)) )

#define VSCREENMSG2(Param1,Param2) (GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, *(JOYSTR_CUR_CLASS_LINE + ": " + Param1 + " " + Param2)) )

#define VSCREENMSGF(Param1,Param2) (GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, *(JOYSTR_CUR_CLASS_LINE + ": " + Param1 + " " + FString::SanitizeFloat(Param2))) )

//UE_LOG Messages!
#define V_LOG(Param1) UE_LOG(Joy,Warning,TEXT("%s: %s"), *JOYSTR_CUR_CLASS_LINE, *FString(Param1))
#define V_LOG2(Param1,Param2) UE_LOG(Joy,Warning,TEXT("%s: %s %s"), *JOYSTR_CUR_CLASS_LINE, *FString(Param1),*FString(Param2))
#define V_LOGF(Param1,Param2) UE_LOG(Joy,Warning,TEXT("%s: %s %f"), *JOYSTR_CUR_CLASS_LINE, *FString(Param1),Param2)

```

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [February 10, 2015, 5:14pm UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/222 "2015-02-10T17:14:42Z")

</div>

\*\*Featured Wiki

Read and Write to Config Files in UE4 C++!\*\*

In wiki I give you code that lets you read and write to config files any time you want, more so than just using UPROPERTY(config)

You can read and write any value you want, any time, directly in UE4 C++!

**End result:** a Human-readible, Human-editable file that your players can tweak to adjust your game’s settings after release!

**Wiki Link**  
[https://wiki.unrealengine](https://wiki.unrealengine)./Config\_Files,_Read_%26\_Write\_to\_Config\_Files

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [February 12, 2015, 9:03pm UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/223 "2015-02-12T21:03:09Z")

</div>

\*\*New Wiki!

AI Navigation in C++, Customize Path Follwing Every Tick!\*\*

Shows you how to extend UE4’s wonderful AI Path Folllowing foundation by adding your own C++ that will run every tick that the path following is occurring!

lets you add to UE4 Path Following without having to rewrite the whole thing from scratch, you can inject your own code per-tick into the standard UE4 path following code!

I used what I share in the wiki below to make c++ dynamic jump pathing, as shown in the AI videos in my signature.

**UE4 Wiki Link**  
[https://wiki.unrealengine](https://wiki.unrealengine)./AI\_Navigation\_in\_C%2B%2B,\_Customize\_Path\_Following\_Every\_Tick

Enjoy!

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [February 19, 2015, 7:32am UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/224 "2015-02-19T07:32:29Z")

</div>

**Example Of Template Functions**

I make extensive use of C++ Template functions in my Min/of Array, full code here!

**Min/of Array Forum Link**  
[https://forums.unrealengine](https://forums.unrealengine)./showthread.php?20212-Two-new-Math-functions-for-you-from-me-in-4-3-Template-Min-Max-of-Array&p=98583&viewfull=1#post98583

**Wiki on C++ Templates**  
[https://wiki.unrealengine](https://wiki.unrealengine)./Templates\_in\_C%2B%2B

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [February 23, 2015, 11:06pm UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/225 "2015-02-23T23:06:12Z")

</div>

\*\*How To

Add Handcrafted Custom Math Curves From UE4 Editor to C++\*\*

Here’s a tutorial on how to construct perfect hand crafted curves in the Editor and then bring them into C++!

You can thus create spring curves, dampen curves, bounce curves, any kind of curves you want, and then use them to drive your C++ code!

[https://wiki.unrealengine](https://wiki.unrealengine)./Curves,\_Create\_Custom\_Cubic\_Curves\_In\_Editor\_For\_Use\_In\_Code

---

<div class="post-metadata">

**Author:** ![TAN](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TAN](https://forums.unrealengine.com/u/TAN)\
**Post date:** [February 24, 2015, 12:14pm UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/226 "2015-02-24T12:14:34Z")

</div>

[=;227791]  
\*\*How To

Add Handcrafted Custom Math Curves From UE4 Editor to C++\*\*

Here’s a tutorial on how to construct perfect hand crafted curves in the Editor and then bring them into C++!

You can thus create spring curves, dampen curves, bounce curves, any kind of curves you want, and then use them to drive your C++ code!

[https://wiki.unrealengine](https://wiki.unrealengine)./Curves,\_Create\_Custom\_Cubic\_Curves\_In\_Editor\_For\_Use\_In\_Code

[/]

Wow 😃 Now that is creative 😃

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [February 28, 2015, 1:00pm UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/227 "2015-02-28T13:00:03Z")

</div>

[=TAN\_;228147]  
Wow 😃 Now that is creative 😃  
[/]

Hee hee!

Glad you liked!

Custom Handcrafted Math Curves in C++ for !  
[https://wiki.unrealengine](https://wiki.unrealengine)./Curves,\_Create\_Custom\_Cubic\_Curves\_In\_Editor\_For\_Use\_In\_Code

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 5, 2015, 5:46pm UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/228 "2015-03-05T17:46:28Z")

</div>

**Link to PhysX 3.3 Source Code For All UE4 Devs**

I’ve updated my PhysX Wiki to include the direct link to the PhysX entire source code!

**As a UE4 developer, you now have access to the entire PhysX C++ source code!**

\*\* Wiki, Integrating PhysX Code into Your Project\*\*  
[https://wiki.unrealengine](https://wiki.unrealengine)./PhysX,\_Integrating\_PhysX\_Code\_into\_Your\_Project#PhysX\_3.3\_Source\_Code\_For\_UE4\_Developers

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 6, 2015, 10:36am UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/229 "2015-03-06T10:36:48Z")

</div>

**Garbage Collection and Dynamic Memory Allocation**

In wiki I show you how you can prevent your runtime-spawned UObjects from getting garbage collected prematurely!

includes things like spawned emitters / Particle System Components, decals, and your own custom UObject systems!

I also go over how to allocate memory yourself and also free it, so you can do your own memory management.

Enjoy!

**Garbage Collection and Dynamic Memory Management**  
[https://wiki.unrealengine](https://wiki.unrealengine)./Garbage\_Collection\_%26\_Dynamic\_Memory\_Allocation

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 9, 2015, 4:59pm UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/230 "2015-03-09T16:59:25Z")

</div>

**Creating Custom Level Blueprints in C++**

Here’s a wiki on how you can make your own C++ Level Blueprints so that you can easily store and access variable data for levels in C++!

You can also make your own functions specifically for your game, that your level designers can then use, that are backed by the power of C++!

**Creating Custom Level Blueprints in C++**  
[https://wiki.unrealengine](https://wiki.unrealengine)./Solus\_C%2B%2B\_Tutorials#Solus\_C.2B.2B\_Tutorial:\_Creating\_Custom\_Level\_Blueprints\_in\_C.2B.2B

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 14, 2015, 12:33am UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/231 "2015-03-14T00:33:59Z")

</div>

**e Custom Console Commands in C++ to be implemented in Blueprints!**

Empower your whole team to make their own console commands in Blueprints!

[https://wiki.unrealengine](https://wiki.unrealengine)./Solus\_C%2B%2B\_Tutorials#How\_to\_Make\_Custom\_BP-Defined\_Console\_Commands

I originally designed at the request of Hourences for use in Solus!

Enjoy!

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 19, 2015, 1:56am UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/232 "2015-03-19T01:56:08Z")

</div>

**[FONT=Comic Sans MS]USTRUCTS, UE4 C++ Structs**

**[UE4 C++ Structs](https://wiki.unrealengine./Structs,_USTRUCTS(),_UE4_C%2B%2B_Structs)**

[https://wiki.unrealengine](https://wiki.unrealengine)./Structs,\_USTRUCTS(),\_UE4\_C%2B%2B\_Structs

[FONT=Comic Sans MS] **I love UStructs!**

🙂

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 19, 2015, 8:06am UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/233 "2015-03-19T08:06:55Z")

</div>

**New Wiki Section, Getting Nav Polys!**

I’ve added a section showing you how to get the Nav Polys, the actual individual units of the nav mesh system, so you can do completely custom calculations like I do in video below!

[https://youtube](https://youtube)./watch?v=sMMSQdnyt6o

**Wiki: Custom UE4 C++ AI Coding**  
[https://wiki.unrealengine](https://wiki.unrealengine)./AI\_Navigation\_in\_C%2B%2B,\_Customize\_Path\_Following\_Every\_Tick#How\_to\_Get\_All\_UE4\_Navigation\_Polys

Enjoy!

---

<div class="post-metadata">

**Author:** ![Jambax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jambax/32/904177_2.png) [@Jambax](https://forums.unrealengine.com/u/Jambax)\
**Post date:** [March 22, 2015, 11:29am UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/234 "2015-03-22T11:29:02Z")

</div>

Added a second tutorial, how to get the screen-size of any actor 🙂 Useful for scaling widgets like the image below:

 ![Untitled-1.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/f/9/f9ebc571402e12dcd90aa148a4294360e06cae83.jpeg)

**Get Screen-Size Bounds of An Actor**  
[https://wiki.unrealengine](https://wiki.unrealengine)./Get\_Screen-Size\_Bounds\_of\_An\_Actor

Hope it helps people!

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 23, 2015, 9:31pm UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/235 "2015-03-23T21:31:41Z")

</div>

@anonymous_user_9c39f750 Jamsh

**Thanks for your awesome wiki contribution, wohooo! Really useful!**

```auto

**Use C++ Operator New Instead of Malloc**

Using Malloc does not initialize the Vtable! So virtual functions will crash!

I recommend that you use C++ operator **new** to get around , which both

a. calls the constructor of the data type
b. properly initializes the VTable (virtual function table)

I updated my wiki with information

**UE4 Dynamic Memory Management**
https://wiki.unrealengine./Garbage_Collection_%26_Dynamic_Memory_Allocation#Every_New_Must_Have_a_Delete

♥
```

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 30, 2015, 11:32am UTC](https://forums.unrealengine.com/t/wiki-code-tutorials/256/236 "2015-03-30T11:32:10Z")

</div>

Dear Community,

I recently wrote a wiki on how to add to the UE4 C++ AI path following system, to add in custom pathing coding!

**UE4 Wiki Link: Writing Custom C++ AI Code**  
[https://wiki.unrealengine](https://wiki.unrealengine)./AI\_Navigation\_in\_C%2B%2B,\_Customize\_Path\_Following\_Every\_Tick

Well I now have my best demo yet of the effectiveness of coding structure!

I prove to you in the video that I am using just multi-threaded C++ to dynamically calculate AI Jump paths for my AI units to follow the player through many complex jumping sequences!

1. I am using just C++ coding, no helpers in the editor!

2.\*\* In thread I share my own UE4 C++ code with you\*\* for how to get all the nav polys, the actual portions of the nav mesh so that you can do your own fancy custom UE4 C++ AI pathing code!

1. In thread I also show you how I know when the UE4 pathing system can’t find a way to the player without doing jumps!

```auto

**Video: 's Multi-Threaded C++ AI Jump Pathing**

https://youtube./watch?v=sMMSQdnyt6o

Once again, I am doing all the jumping calculations **dynamically via C++** using the nav areas and my custom path following component!

```

**Mult-Threaded**

The code I use in video is multi-threaded using the UE4 C++ Task Graph system:

**UE4 Wiki Link: UE4 Multi-threading**  
[https://wiki.unrealengine](https://wiki.unrealengine)./Multi-Threading:\_Task\_Graph\_System

````auto

**C++ Code For You**

I inject my custom AI jump pathing code in way:

```

/*
        Custom UE4 C++ AI Path Follow Component

	By

*/

#pragma once

//Super
#include "Navigation/PathFollowingComponent.h"		

UCLASS() 
class UJoyPathFollowComp : UPathFollowingComponent
{
	GENERATED_BODY()
:
	UJoyPathFollowComp(const FObjectInitializer& ObjectInitializer);

/** follow current path segment */
virtual void FollowPathSegment(float DeltaTime) override;

};

```

```

void UJoyPathFollowComp::FollowPathSegment(float DeltaTime)
{
	//Pointer Safety Checks
	if (MovementComp == NULL || !Path.IsValid())
	{
		return;
	}
	// ~~~~~~~~~~~~~~~~~~~~~~~~~
	 
	
	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Use Jump/Fall Pathing?
	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
	if(Path->IsPartial()) //AI could not reach player, try using jump pathing!
	{
                //I send out instructions to my custom character class here
		JoyChar->ReceiveJumpFallPathingRequest();
	
		return;
		//~~~
	}
	
	
	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//Proceed normally (no jump pathing)
	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Super::FollowPathSegment(DeltaTime);
}

```

````

**Explanation**

**FollowPathSegment** is the UE4 Path Follow tick function, and so when you want to add completely custom coding you can use function as your starting point to adjust normal UE4 pathing behavior!

**Path is Partial**

The way I tell whether I need to try using custom jump pathing code is whether or not the UE4 Pathing system has detected a partial path!

Then my AI jump code runs and teaches the AI to get to the player using C++ calculated Jumps!

```auto

if(Path->IsPartial()) //AI could not reach player, try using jump pathing!

```

````auto

**How to Get all the UE4 Nav Polys**

In the video above you will see I get all the UE4 Nav Polys in order to do all my C++ AI Jump calculations!

Here's the function I wrote to do , just for you!

```

**// UE4 C++ AI Code for you!
// add to your custom path follow component!**

**//Nav Data**
FORCEINLINE const ANavigationData* **GetMainNavData** (FNavigationSystem::ECreateIfEmpty CreateNewIfNoneFound)
{
	UNavigationSystem* NavSys = GetWorld()->GetNavigationSystem();
	if(!NavSys) return NULL; 
	return NavSys->GetMainNavData(CreateNewIfNoneFound);
}

**//Choose Which Nav Data To Use**
FORCEINLINE const ANavigationData* **JoyGetNavData()** const
{
        if(!MovementComp)
        {
              return GetMainNavData();
        }

	const FNavAgentProperties& AgentProperties = MovementComp->GetNavAgentPropertiesRef() ;
	const ANavigationData* NavData = GetNavDataForProps(AgentProperties) ;
	if (NavData == NULL)
	{
		VSCREENMSG("ERROR USING NAV DATA"); 
		NavData = GetMainNavData();
	}
		   
	return NavData;
}

//VERY IMPORTANT FOR CRASH PROTECTION !!!!!
FORCEINLINE bool **TileIsValid** (const ARecastNavMesh* NavMesh,int32 TileIndex) const
{
	if(!NavMesh) return false;
	// ~~~~~~~~~~~~~~
	const FBox TileBounds = NavMesh->GetNavMeshTileBounds(TileIndex);
	
	return TileBounds.IsValid != 0;
}

bool **NavPoly_GetAllPolys** (TArray<NavNodeRef>& Polys);

```

```

**//'s UE4 Nav code to get all the nav polys!**

bool UJoyPathFollowComp:: ****NavPoly_GetAllPolys**** (TArray<NavNodeRef>& Polys)
{
	if(!MovementComp) return false;
	// ~~~~~~~~~~~~~~~~~~
	
	//Get Nav Data
	const ANavigationData* NavData = JoyGetNavData();
	 
	const ARecastNavMesh* NavMesh = Cast<ARecastNavMesh>(NavData);
	if(!NavMesh)
	{
		return false;
	}
	
	TArray<FNavPoly> EachPolys;
	for(int32 v = 0; v < NavMesh->GetNavMeshTilesCount(); v++)
	{
		
                //CHECK IS VALID FIRST OR WILL CRASH!!! 
               // 256 entries but only few are valid!
               // using continue in case the valid polys are not stored sequentially!
		if( ****!TileIsValid**** (NavMesh,v)) 
                {
                    continue;
		}	
	
		NavMesh->GetPolysInTile(v,EachPolys);
	}	
	  
	
	//Add them all!
	for(int32 v = 0; v < EachPolys.Num(); v++)
	{
		Polys.Add(EachPolys[v].Ref);
	}
}

```

````

**Enjoy!**

Have fun writing custom UE4 AI C++ code and getting all the nav polys so you can truly do whatever you want with UE4’s awesome navigation system!

[https://www.mediafire](https://www.mediafire)./convkey/a416/xh2a0w6qocsc9xb6g.jpg

[Previous page](https://forums.unrealengine.com/t/wiki-code-tutorials/256.md?page=10)

[Next page](https://forums.unrealengine.com/t/wiki-code-tutorials/256.md?page=12)
