Skip to content

Instantly share code, notes, and snippets.

@dave-newson
Last active August 29, 2015 14:23
Show Gist options
  • Save dave-newson/7d02ba5dcf6a214ce1ae to your computer and use it in GitHub Desktop.
Save dave-newson/7d02ba5dcf6a214ce1ae to your computer and use it in GitHub Desktop.
UE4 Code Snippets
// 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;
// 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);
/** 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);
// 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);
// 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