Download

Wiki Code Tutorials

Get Float As String With Precision Using Epic’s FText Helpers

Dear Community,

I’ve updated my Get Float As String With Precision C++ wiki to use Epic’s FText helpers!

Now I am leveraging all of their awesome work to get a float as a string with any precision of your choosing, encapsulatd into an easy to use static library function.

My function also now gives you an option as to whether you want to include a leading zero for fractional numbers!

UE4 Wiki Link

Enjoy!

:slight_smile:

Rama

**Featured Wiki

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

In this 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
A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums,Read%26_Write_to_Config_Files

:slight_smile:

Rama

How To Do Custom C++ Logic in Animation Blueprints, Every Tick!

In this wiki I show you how you can add custom project-level C++ code to your Animation Blueprints!

This is code that you can run every animation tick!

This allows you as the C++ programmer to support your entire time by doing intense math calculations in C++, which is much faster than in BP!

This also lets you utiilze your entire C++ code base and custom data structures without having to expose it all to BP so that the animation blueprint can use it in the event graph!

Custom C++ Logic for Animation Blueprints

Enjoy!

:slight_smile:

Rama

Thank you Rama for your great work! :slight_smile:

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?