Wiki Code Tutorials

**New Wiki Section

Shorthand Forward Declaration**

I added a new section and also polished up my Forward Declaration Wiki!

Forward Declaration ~ Shorthand Forward Declaration
https://wiki.unrealengine./Forward_Declarations#Shorthand_Forward_Declaration

:slight_smile:

Just added another tutorial of my own, Spawning different Pawns for different Players in Multiplayer!

https://wiki.unrealengine./Spawn_Different_Pawns_For_Players_in_Multiplayer

Hope helps people :slight_smile:

[=;265933]
Just added another tutorial of my own, Spawning different Pawns for different Players in Multiplayer!

https://wiki.unrealengine./Spawn_Different_Pawns_For_Players_in_Multiplayer

Hope helps people :slight_smile:
[/]

Thanks for sharing !

:slight_smile:

Tutorial: How to use UPhysicsConstraintComponent inside OnConstruction(FTransform) override function

I wanted to try contributing to the wiki with a tutorial. I noticed that had already made an article here in regards to Physics Constraint Components and creating them dynamically. All I wanted to do is to just extend that article, so it also touches on ObjectInitializer, why we shouldnā€™t initialize physics constraint components in OnConstruction(Transform) function (which I really donā€™t know), and other ways to dynamically create physics constraint components.

If I editā€™s article, it will easily get reverted because I do not have a polished code at the moment. Therefore, I will be posting my extension here, and hopefully someone could give me tips. Feedback is welcomed.

[HR][/HR]

I wanted to be able to spawn actors and constrain the actors in a given space like a chain or a line from my base class to the end. I know that to spawn actors, I need to call on SpawnActor() any function that is not going to be called in the constructor. However, I am having trouble with the UPhysicsConstraintComponent where it would fail to be created when I call on CreateDefaultSubobject() in the OnConstruction(Transform) override function of my base class. The only thing I know that will allow me to set UPhysicsConstraintComponent successfully is by initializing it in the constructor.

I did another alternate method where I would store three TArrays in the base class, with each of them representing the subclass, physics constraint component, and the constraint names. The following code is placed in the base classā€™ header file. I use APawn because, frankly, everything is in APawn.



UCLASS()
class TUTORIAL_API ABaseClass :  APawn
{
	GENERATED_BODY()
:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=CustomProperties) TArray<ASubClass*> SubClassArray;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=CustomProperties) TArray<UPhysicsConstraintComponent*> PhysicsConstraintArray;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=CustomProperties) TArray<FName> ConstraintNameArray;
	...
	...
}


Then to initialize the arrays, first you need to create the following components for the PhysicsConstraintArray and the ConstraintNameArray.



ABaseClass::ABaseClass(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
	for (int32 i = 0; i < 4; i++){
		//Names
		FString Name = "Frame_" + FString::FromInt(i);
		->ConstraintNameArray.Push(FName(*Name));

		//Physics Constraints
		UPhysicsConstraintComponent* PhysicsConstraint = ObjectInitializer.CreateDefaultSubobject<UPhysicsConstraintComponent>(, ->ConstraintNameArray*);
		PhysicsConstraint->SetWorldLocation(->GetActorLocation());
		->PhysicsConstraintArray.Push(PhysicsConstraint);
	}
	
	...
	...
}


Then in the OnConstruction(Transform) override function, you would then start initializing the subclass array. Note that the ConstraintNameArray.Num() is then used as an array size counter, so you donā€™t have to define constants here and there.



void ABaseClass::OnConstruction(const FTransform& Transform){
	Super::OnConstruction(Transform);

	//First loop needs initial values passed in, so successive calls can then be swapped for last initialized actors.
	FVector Height(0.0f, 0.0f, 100.0f); //How high from the initial world origin. Since the default floor mesh in a blank level is 80 UE4 units high, I set it to 100.
	FActorSpawnParameters Params;
	Params.Owner = ; //Setting the owner as the base class. When spawning actors, actors will have the owner as their parents.
	USceneComponent* Scene = ->GetRootComponent();
	UPrimitiveComponent* Primitive = ->BoxCollider;

	//Initializing Subclass array.
	for (int32 i = 0; i < ConstraintNameArray.Num(); i++){
		ASubClass* Class = ->GetWorld()->SpawnActor<ASubClass>(ASubClass::StaticClass(), Height, ->GetActorRotation(), Params);
		Class->BoxCollider->AttachTo(Params.Owner->GetRootComponent());
		
		//Set whatever constraining limits you need here
		UPhysicsConstraintComponent* Physics = ->PhysicsConstraintArray*;
		Physics->AttachTo(Scene, NAME_None, EAttachLocation::KeepWorldPosition);
		Physics->SetConstrainedComponents(Primitive, NAME_None, Class->BoxCollider, NAME_None);
		Physics->SetAngularSwing1Limit(EAngularConstraintMotion::ACM_Locked, 0.0f);
		Physics->SetAngularSwing2Limit(EAngularConstraintMotion::ACM_Locked, 0.0f);
		Physics->SetAngularTwistLimit(EAngularConstraintMotion::ACM_Locked, 0.0f);
		
		//Prepare for next iteration.
		Params = {};
		Params.Owner = Class;
		Scene = Class->GetRootComponent();
		Primitive = Class->BoxCollider;
	}
	
	...
	...
}


That is all.

Hi All,

I just created a tutorial on making an editor module https://wiki.unrealengine./Creating_an_Editor_Module. I hope someone finds it useful!

is my first tutorial so let me know if there is anything I should be doing differently in terms of style.

Iā€™ve got another one coming up on component visualizers and then maybe one on custom editor modes if Iā€™ve still got the energy.

Hi All Again,

As promised Iā€™ve made another tutorial on using component visualizers: https://wiki.unrealengine./Component_Visualizers. Please feel free to give me some feedback on it!

These are awesome! Nice work :slight_smile:

New Tutorial, how to clear UMG Widgets between opening/closing levels.

Note: is probably a workaround for a bug. I would Submit a Pull Request, but Iā€™m not sure how!

https://wiki.unrealengine./Clear_Widgets_When_Switching_Levels

**New Wiki

How to Use a Custom Skeletal Mesh Component Class with your ACharacter Extending Class!**
https://wiki.unrealengine./Custom_Character_Mesh_Class

In tutorial I show you how you can easily change your ACharacter class to use a custom USkeletalMeshComponent at any time during your projectā€™s development cycle!

No custom APawn class tree required! Just a simple change to your ACharacter constructor!

Class and Line Number for your Screen and Log Messages!

Dear Community,

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./Logs,_Printing_the_Class_Name,_Function_Name,_Line_Number_of_your_Calling_Code!#My_C.2B.2B_Code_For_You


**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! ā™„ 
}


```



UE_LOG Versions

Iā€™ve also added several macros to support adding class and line number information to UE_LOG messages!



//will print the class and line number along with the character name!
V_LOG2(YourLogCat, "Hit Character Name is",Hit.GetActor()->GetName());



**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:



```


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


```





```


/*
	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!
#define V_LOG(LogCat, Param1) 		UE_LOG(LogCat,Warning,TEXT("%s: %s"), *JOYSTR_CUR_CLASS_LINE, *FString(Param1))
 
#define V_LOG2(LogCat, Param1,Param2) 	UE_LOG(LogCat,Warning,TEXT("%s: %s %s"), *JOYSTR_CUR_CLASS_LINE, *FString(Param1),*FString(Param2))
 
#define V_LOGF(LogCat, Param1,Param2) 	UE_LOG(LogCat,Warning,TEXT("%s: %s %f"), *JOYSTR_CUR_CLASS_LINE, *FString(Param1),Param2)
 
#define V_LOGM(LogCat, FormatString , ...) UE_LOG(LogCat,Warning,TEXT("%s: %s"), 	*JOYSTR_CUR_CLASS_LINE, *FString::Printf(TEXT(FormatString), ##__VA_ARGS__ ) )


```



Enjoy!

:)

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
https://wiki.unrealengine./Float_as_String_With_Precision

Enjoy!

:slight_smile:

**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./Config_Files,Read%26_Write_to_Config_Files

:slight_smile:

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

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

is code that you can run every animation tick!

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!

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
https://wiki.unrealengine./Animation_Blueprint,_Implement_Custom_C%2B%2B_Logic_Via_Tick_Updates

Enjoy!

:slight_smile:

Thank you for your great work! :slight_smile:

[=;301969]
Thank you for your great work! :slight_smile:
[/]

Hee hee!

Youā€™re welcome!

Have fun today!

:slight_smile:

**Creating Dynamic Physics Constraints During Runtime

My Physics Library Functions Included!**

https://wiki.unrealengine./Physics_Constraints,_Create_New_Constraints_Dynamically_During_Runtime

:slight_smile:

Thanks for the code tutorials!!!

[=danjedi;313280]
Thanks for the code tutorials!!!
[/]

Youā€™re welcome danjedi!

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

:slight_smile:

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

[=StewieYan;324264]
thank you for your effort, but I really hope the material can be organized more like a book, with a proper learning order.
[/]

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

Until then I recommend start with:

Entry Level Guide to UE4
https://wiki.unrealengine./Entry_Level_Guide_to_UE4_C%2B%2B

Now available in Russian!
https://wiki.unrealengine./Entry_Level_Guide_to_UE4_C%2B%2B_RUS

:slight_smile: