Download

Wiki Code Tutorials

Hee hee!

You’re welcome!

Have fun today!

:slight_smile:

Rama

**Creating Dynamic Physics Constraints During Runtime

My Physics Library Functions Included!**

:slight_smile:

Rama

Thanks for the code tutorials!!!

You’re welcome danjedi!

[FONT=Comic Sans MS]Welcome to the UE4 Forums!

:slight_smile:

Rama

thank you for your effort, but I really hope the material can be organized more like a book, with a proper learning order.

Entry Level Guide to UE4

I am indeed working on a UE4 C++ book, so great idea :slight_smile:

Until then I recommend everyone start with:

Entry Level Guide to UE4

Now available in Russian!

:slight_smile:

Rama

Blueprint Native Event

Dear Community,

Here is my new wiki tutorial on Blueprint Native Events!

BP Native Events allow you to have a core C++ implementation that can be overridden / extended in BP by your team mates!

Blueprint Native Events

:slight_smile:

Rama

Before I invest time into this, will the tutorials on the first post work with 4.8?

If you find a tutorial is not compiling in 4.8 just let me know!

If you find any uses of



(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)


replace it with



(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)


Epic has been providing absolutely wonderful compiler error / deprecation warnings since about 4.6, so most likely if something is out of date, the compiler will tell you exactly what to do.

:slight_smile:

Rama

Animated Vertex Positions With Movement Velocity Correction

Dear Community,

I’ve released a new wiki on how you can obtain animated vertex positions of character meshes!


**C++ Code For You**

Here's the code I just finished writing to obtain accurate animated character vertex positions!



```


bool UVictoryBPFunctionLibrary::AnimatedVertex__GetAnimatedVertexLocations(
	USkeletalMeshComponent* Mesh, 
	TArray<FVector>& Locations,
	bool PerformPawnVelocityCorrection
){
	if(!Mesh || !Mesh->SkeletalMesh)  
	{
		return false;
	}

	//~~~~~~~~~~~~~
	Locations.Empty(); 
	//~~~~~~~~~~~~~
	 
	Mesh->ComputeSkinnedPositions(Locations);
	
	FTransform ToWorld = Mesh->GetComponentTransform();
	FVector WorldLocation = ToWorld.GetLocation();
	
	//Pawn Velocity Correction
	UPawnMovementComponent* MovementComp = nullptr;
	if(PerformPawnVelocityCorrection)
	{
		APawn* Pawn = Cast<APawn>(Mesh->GetOwner());
		MovementComp = (Pawn) ? Pawn->GetMovementComponent() : NULL;
	}
	bool DoVelocityCorrection = PerformPawnVelocityCorrection && MovementComp;
	//Pawn Velocity Correction
	 
	for(FVector& Each : Locations)
	{
		Each = WorldLocation + ToWorld.TransformVector(Each);
		if(DoVelocityCorrection)
		{
			Each += MovementComp->Velocity * FApp::GetDeltaTime();
		} 
	} 
	
	return true;
}


```



Enjoy!

:)

Rama

New Wiki Tutorial: How to create a blueprint node for sorting an array of Actors by field value.

Awesome!..

Thanks for sharing Nimgoble!

:slight_smile:

:slight_smile:

:slight_smile:

Rama

Finding out Which Streamed Level an Actor is In

Dear Community,

I’ve gone back and updated one of my earliest wikis.

Streamed Levels, Test If Actor Is In Level Bounds

This is a wiki on how to find out which streamed level an actor is contained in, during runtime!

My old code obtained the StreamingLevels array by pointer, and my new method retrieves the array by reference.

Notice how much simpler the code becomes when getting by reference!

I also use a ranged for loop to simplify the code even more :slight_smile:


**New Version**



```


//Getting the array by reference!
const TArray<ULevelStreaming*>& StreamedLevels = GetWorld()->StreamingLevels;

for(const ULevelStreaming* EachLevelStreaming : StreamedLevels)
{
	if( !EachLevelStreaming) 
	{
		continue;
	}
	
	ULevel* EachLevel =  EachLevelStreaming->GetLoadedLevel();
	
	//Is This Level Valid and Visible?
	if( !EachLevel || !EachLevel->bIsVisible) 
	{
		continue;
	}
		 
	//Print Name of current Level Streaming to know which level the unit is in!
	ClientMessage( EachLevelStreaming->GetWorldAssetPackageName() );
	  
	//Is the Player Location Within this Level's Bounds
	if(ALevelBounds::CalculateLevelBounds(EachLevel).IsInside(GetPawn()->GetActorLocation()))
	{
		ClientMessage("Yes Player Is Within This Level");
	}
}


```


Original Code



//Get the Currently Streamed Levels
TArray<ULevelStreaming*>* StreamedLevels = &GetWorld()->StreamingLevels;
 
ULevel* EachLevel = NULL;
for(int32 v=0; v < StreamedLevels->Num(); v++)
{
	if( ! (*StreamedLevels)[v]) continue;
	//~~~~~~~~~~~~~~~~
 
	EachLevel =  (*StreamedLevels)[v]->GetLoadedLevel();
	if(!EachLevel) continue;
	//~~~~~~~~~~~~
 
	//Is This Level Visible?
	if(!EachLevel->bIsVisible) continue;
	//~~~~~~~~~~~~~~~~~~~
 
	//Print Package Name For this Level!
	ClientMessage( (*StreamedLevels)[v]->PackageName.ToString());
 
	//Is the Player Location Within this Level's Bounds
	if(ALevelBounds::CalculateLevelBounds(EachLevel).IsInside(GetPawn()->GetActorLocation()))
	{
		ClientMessage("Yes Player Is Within This Level");
	}
}



**Obtaining Streaming Level Name**

Please note I've adjusted the code to 4.8 so you can tell which streaming level the actor is in!



```


//Print Name of current Level Streaming to know which level the unit is in!
ClientMessage( EachLevelStreaming->**GetWorldAssetPackageName**() );


```



Enjoy!

:)

Rama

AI Dodge Wiki

Dear Community,

I’ve put up a wiki on how to quickly and easily implement an AI dodge mechanic!

I discuss:

  1. Obtaining the perpedicular to the direction of the AI unit to its target

  2. Picking which way to dodge

  3. Choosing how far to dodge along the perpedicular

  4. How to ensure the UE4 Navigation System will find the dodge point on the nav mesh

  5. How to do all this easily using FVector::RotateAngleAxis


**My C++ Code For You**



```


void AIDodge(bool DodgeRight=true, float Distance=256); //.h
 
void AYourAIClass::AIDodge(bool DodgeRight, float Distance) 
{
	//Location of unit who wants to dodge sideways, presumed to be facing target already
	FVector UnitLocation = GetActorLocation();
	FVector DirectionToActor = (OtherActor->GetActorLocation() - UnitLocation ).GetSafeNormal();
 
	//Optional, Ensure UE4 Nav mesh point will be found.
	DirectionToActor.Z = 0;
 
	//Rotate the direction by 90 to get perpendicular of direction to actor
	FVector Perpendicular = DirectionToActor.RotateAngleAxis(90,FVector(0,0,1));
 
	//Dodging to relative Left or Right?
	Perpendicular *= (DodgeRight) ? 1 : -1;
 
	//Tell Unit to move 256 units along this perpendicular
	FVector GoalLocation = UnitLocation + Perpendicular * Distance;
 
	//Tell unit to move to this location
	AAIController* AIControl = Cast<AAIController>(GetController());
	if(AIControl)
	{
	  AIControl->MoveToLocation(GoalLocation,0); //Optional Acceptance Radius
	}
}


```



Enjoy!

Rama

how would you go about decompressing the file and then loading the saved info?

I show you how to decompress and load the data in this section of my Binary Save System wiki:

Loading Compressed Binary Data
A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums,Read%26_Write_Any_Data_to_Compressed_Binary_Files#Loading_Compresse


**C++ Code For You**

Here's the code most relevant to your question:



```


//Load the Compressed data array
	TArray<uint8> CompressedData;
	if (!FFileHelper::LoadFileToArray(CompressedData, *FullFilePath))
	{
		Optimize("FFILEHELPER:>> Invalid File");
		return false;
		//~~
	}
 
	// Decompress File 
	FArchiveLoadCompressedProxy Decompressor = 
		FArchiveLoadCompressedProxy(CompressedData, ECompressionFlags::COMPRESS_ZLIB);
 
	//Decompression Error?
	if(Decompressor.GetError())
	{
		Optimize("FArchiveLoadCompressedProxy>> ERROR : File Was Not Compressed ");
		return false;
		//
	}
 
	//Decompress
	FBufferArchive DecompressedBinaryArray;
	Decompressor << DecompressedBinaryArray;
 
	//~
	//		  Read the Data Retrieved by GFileManager
	//~
 
	FMemoryReader FromBinary = FMemoryReader(DecompressedBinaryArray, true); //true, free data after done
	FromBinary.Seek(0);

	SaveLoadData(FromBinary,NumGemsCollected,PlayerLocation,ArrayOfRotationsOfTheStars);


```



SaveLoadData uses the Memory Reader Archive to put the supplied data back in the variables, which are passed in by reference.

You could also pass in a UStruct or an actor that was spawned and then fill in the appropriate variable data that way!

Enjoy!

:)

Rama

AI Navigation, Custom Pathing Using Nav Modifiers, Nav Area Classes, and Query Filters

Dear Community,

I’ve just released a new wiki on how to use Nav Modifiers and Query Filters!

Wiki Link


**Video**

https://youtube.com/watch?v=xwdVQQtQa8s

Use Case: Electric Currents and 2 Types of Characters

In my example, I have two types of units.

The blue unit is immune to electricity, and does not need to path around electric currents.

The red unit bids us all a fond farewell if it passes thruogh an electric current.

So in this case I can’t just block of areas that have electric currents completely from the nav mesh, or else the blue unit cannot pass through freely as it should be able to, taking a shortcut as a result.

This is a case where Nav Modifiers and Query Filters really shine!

I only want to filter out certain sections of the nav mesh for the red unit, while still allowing the blue unit to pass through those areas freely.


**C++ Code**

Here's the code I used to make a BP Node that allows you to use custom Navigation Query Filters in Blueprints!

Notice the in-Editor documentation!

//.h


```


/** Move to Location with optional Query Filter! 
*
* 1. Create Custon Nav Area Classes. 
*
* 2. Use Nav Modifier Volumes to apply custom area class data within the level, then
*
* 3. Create Query Filters which alter/exclude those custom nav areas. 
*
* 4. Can then choose to use the filters per character or even per Move To using this node. 
*
*  <3 Rama
*
* @param FilterClass - Allows different types of units to path in different ways all the time, or path differently per Move To using this node!
* @param bProjectDestinationToNavigation - Whether to attempt to find a nearby point on the nav mesh below/above/close to the supplied point. Uses the Agent's Nav Extent for the projection
* @param bStopOnOverlap - Add pawn's radius to AcceptanceRadius
* @param bCanStrafe - Set focus related flag: bAllowStrafe
* @return Whether the Pawn's AI Controller is valid and goal can be pathed to
*/ 
UFUNCTION(BlueprintCallable, Category = "VictoryBPLibrary|AI Move To")
static EPathFollowingRequestResult::Type Victory_AI_MoveToWithFilter(
	APawn* Pawn, 
	const FVector& Dest, 
	TSubclassOf<UNavigationQueryFilter> FilterClass = NULL,
	float AcceptanceRadius = 0,  
	bool bProjectDestinationToNavigation = false,
	bool bStopOnOverlap = false,
	bool bCanStrafe = false
);


```



//.cpp


```


EPathFollowingRequestResult::Type UVictoryBPFunctionLibrary::Victory_AI_MoveToWithFilter(
	APawn* Pawn, 
	const FVector& Dest, 
	TSubclassOf<UNavigationQueryFilter> FilterClass ,
	float AcceptanceRadius , 
	bool bProjectDestinationToNavigation ,
	bool bStopOnOverlap ,
	bool bCanStrafe 
){
	if(!Pawn) 
	{
		return EPathFollowingRequestResult::Failed;
	}
	
	AAIController* AIControl = Cast<AAIController>(Pawn->GetController());
	if(!AIControl) 
	{
		return EPathFollowingRequestResult::Failed;
	} 
	
	return AIControl->MoveToLocation(
		Dest, 
		AcceptanceRadius,
		bStopOnOverlap, 	//bStopOnOverlap
		true,						//bUsePathfinding 
		bProjectDestinationToNavigation, 
		bCanStrafe,			//bCanStrafe
		FilterClass			//<~~~
	);
}


```



Enjoy!

Rama

Ah, i forgot about this thread (always skipping the pinned threads). Gonna post my
simple Session Code Tutorial and examples, as well as explanations here too if i’m allowed!

How to use Sessions in C++!

PS: If it’s not allowed by you Rama, just tell me and i will remove it again. :open_mouth:

Thank you for sharing eXi!

That’s quite the nicely formatted and extensive tutorial on the important topic of Network Game Sessions!

Great work!

:heart:

Rama