Last active
August 29, 2015 14:23
-
-
Save dave-newson/7d02ba5dcf6a214ce1ae to your computer and use it in GitHub Desktop.
UE4 Code Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Code and things. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See Property Specified docs | |
// @link https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Reference/Properties/Specifiers/index.html | |
// Property: Editable, read/write via blueprint, category member | |
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Forces") | |
FVector CenterOfMass; | |
// Function: Callable in Blueprint, category member | |
UFUNCTION(BlueprintCallable, Category = "Game|Components|ProjectileMovement") | |
void AddInputMove(FVector input); | |
// Property: Readonly in Blueprint (can't be removed). Visible only in archetypes. | |
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Vehicle) | |
class UMovementComponent* VehicleMovement; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Onscreen message | |
GEngine->AddOnScreenDebugMessage(-1, fLifespan, FColor::Red, TEXT("Hello, I am annoying.")); | |
// Draw a line | |
DrawDebugLine(GetWorld(), FVectorStart, FVectorTarget, FColor::Red, false, 0.1f, 0, fLifespan); | |
// Draw a sphere | |
DrawDebugSphere(GetWorld(), GetActorLocation(), fRadius, 16, FColor::Red, false, fLifespan); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Header */ | |
DECLARE_LOG_CATEGORY_EXTERN(MyLogCat, Log, All); | |
/** Cpp file */ | |
DEFINE_LOG_CATEGORY(MyLogCat); | |
/** Cpp */ | |
UE_LOG(MyLogCat, Warning, TEXT("target rot p %f r %f y %f"), targetRot.Pitch, targetRot.Roll, targetRot.Yaw); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Location specific force | |
UPrimitiveComponent* BasePrimComp = Cast<UPrimitiveComponent>(AttachParent); | |
BasePrimComp->AddForceAtLocation(WorldForce, GetComponentLocation(), NAME_None); | |
// Impulse | |
const FVector Impulse = FVector(0.f, 0.f, JumpImpulse); | |
BasePrimComp->AddImpulse(Impulse); | |
// Torque | |
const FVector Torque = FVector(0.f, 0.f, 1.0f); | |
BasePrimComp->AddTorque(Torque); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Standard | |
bool myBoolean = true; | |
int32 myInt = 1; | |
float myFloat = 1.f; | |
FString myString = TEXT("Hello World"); | |
// Struct-type | |
FVector myVector = FVector(1.f, 0.f, 0.1f); | |
FVector2D myVector2d = FVector2D(1.f, 2.f); | |
FRotator myRotator = FRotator(1.f, 2.f, 3.f); | |
FColor myColor = FColor(255, 255, 0); | |
// Class and Subclass | |
TClass<AActor> myActorSpecific | |
TSubclassOf<AActor> myActorDerived; | |
// Array of varying subclass objects | |
TArray<TSubclassOf<AActor>> myListOfActors; | |
// Struct | |
struct FMovementAxisDrag | |
{ | |
FVector Move = FVector(100.f, 100.f, 100.f); | |
FRotator Rotate = FRotator(10.f, 10.f, 10.f); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment