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
#pragma once | |
#include "CoreMinimal.h" | |
#include "EngineUtils.h" | |
#include "DrawDebugHelpers.h" | |
inline void DrawDebugQuad(const UWorld* World, const FVector& BotLeft, const FVector& TopLeft, const FVector& TopRight, const FVector& BotRight, const FColor& Color = FColor::Green, const bool bPersistentLines = false, const float LifeTime = -1.0f, const uint8_t DepthPriority = 0, const float Thickness = 0.0f) | |
{ | |
DrawDebugLine(World, BotLeft, TopLeft, Color, bPersistentLines, LifeTime, DepthPriority, Thickness); | |
DrawDebugLine(World, TopLeft, TopRight, Color, bPersistentLines, LifeTime, DepthPriority, Thickness); |
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
const APlayerController* PlayerController = GetWorld()->GetFirstPlayerController(); | |
// Get viewport size | |
int ViewportSizeX, ViewportSizeY; | |
PlayerController->GetViewportSize(ViewportSizeX, ViewportSizeY); | |
// Deproject screen point | |
FVector ShotStart, ShotDirection; | |
PlayerController->DeprojectScreenPositionToWorld(ViewportSizeX * 0.5f, ViewportSizeY * 0.5f, ShotStart, ShotDirection); // Assuming crosshair is in screen center | |
ShotStart += ShotDirection * 100.0f; // Offset a bit so that shot starts from gun end |
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
#include "Kismet/KismetMathLibrary.h" | |
UKismetMathLibrary::MakeRotationFromAxes( ForwardVector, RightVector, UpVector ) |
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
// MyClass.h ============================== | |
UClass *mBlueprintClass = nullptr; | |
// ========================================== | |
// MyClass.cpp ============================== | |
MyClass::MyClass() | |
{ | |
static ConstructorHelpers::FObjectFinder<UBlueprint> blueprint_finder(TEXT("Blueprint'/Game/Path/To/Asset/MyBlueprint.MyBlueprint'")); // This path can be obtained from the editor doing right click + "Copy Reference" | |
if (blueprint_finder) |
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
buttonTwoDatesPayments.setOnClickListener(new View.OnClickListener() { | |
public void onClick(View v) | |
{ | |
Calendar c = Calendar.getInstance(); | |
int mYear = c.get(Calendar.YEAR); | |
int mMonth = c.get(Calendar.MONTH); | |
int mDay = c.get(Calendar.DAY_OF_MONTH); | |
DatePickerDialog datePicker = new DatePickerDialog( MainActivity.act, | |
new DatePickerDialog.OnDateSetListener() |
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
/* | |
There's a function you can call to pause / resume the game in UE4: | |
UGameplayStatics::SetGamePaused(GetWorld(), true); //true = paused, false = resume | |
So you would do something like this: | |
*/ | |
void Pause() | |
{ |
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
// For Components ================================= | |
UFUNCTION() | |
void OnBeginOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult); | |
UFUNCTION() | |
void OnEndOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex); | |
// Register events in BeginPlay | |
OnComponentBeginOverlap.AddDynamic(this, &MyClass::OnBeginOverlap); //Register the BeginOverlap event | |
OnComponentEndOverlap.AddDynamic(this, &MyClass::OnEndOverlap); //Register the EndOverlap event | |
// ================================================= |
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
APlayerCameraManager *camManager = GetWorld()->GetFirstPlayerController()->PlayerCameraManager; | |
FVector camLocation = camManager->GetCameraLocation(); | |
FVector camForward = camManager->GetCameraRotation().Vector(); |
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
#include "DrawDebugHelpers.h" | |
DrawDebugLine(GetWorld(), traceStart, traceEnd, FColor::Green, true, 1.0f); |
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
/* | |
Ok, so you want to change your Object Type (or collision channel) to a custom channel in runtime. | |
But there's a problem, it seems UE4 doesn't support this yet, but there's a workaround hehe :) | |
For example, imagine you create the ObjectType Building. | |
Now, imagine you want to change the ObjectType of all the StaticMeshComponents of the object OBJECT (from WorldStatic to Building, for example). | |
You can try something like this: | |
*/ |
NewerOlder