Skip to content

Instantly share code, notes, and snippets.

View sephirot47's full-sized avatar

Victor Anton Dominguez sephirot47

View GitHub Profile
@sephirot47
sephirot47 / UE4 Common crash causes
Last active August 29, 2015 14:23
UE4 Common crash causes
- GameMode, make sure none of them is null
- Null pointer exceptions
- Having instantiated in the level the same PlayerBP than the one in GameMode
(so when the game starts the GameMode puts another one and it gets duplicated )
- Having BAD CODE(code that can cause a crash), even on startup. Ye, if u have bad code it can crash on startup!!! UE4 does some sort of prebuild or something. Beware of putting code on the constructor that must go in the BeginPlay instead, this happened to me <3
@sephirot47
sephirot47 / UE4 Get Actor's components
Last active August 29, 2015 14:23
UE4 Get Actor's components
UComponentType *myComponent;
TArray<UComponentType*> comps;
actor->GetComponents(comps);
if (comps.Num() > 0) myComponent = comps[0];
@sephirot47
sephirot47 / UE4 Get ALL Actors in the level
Created June 16, 2015 14:10
UE4 Get ALL Actors in the level
//For every actor in this level...
for (TActorIterator<AActor> actor(GetWorld()); actor; ++actor)
{
//Do whatever you want with your actor
actor->BlahBlah();
}
@sephirot47
sephirot47 / UE4 Bind function to Axis Input
Last active August 29, 2015 14:23
UE4 Bind function to Axis Input
//Input name //Function to handle the input
this->InputComponent->BindAxis("MoveForward", this, &UMyActor::HandleVerticalAxis);
void UMyActor::HandleVerticalAxis(float v)
{
//v is the float value for the input
}
@sephirot47
sephirot47 / UE4 Get HUD from anywhere
Created June 17, 2015 20:51
UE4 Get HUD from anywhere
//Supose we are inside a Component ACTOR OF THE COMP.
AREMHUD *hud = Cast<AREMHUD>(UGameplayStatics::GetPlayerController( this->GetOwner(), 0)->GetHUD());
//Custom HUD class: AREMHUD
@sephirot47
sephirot47 / UE4 Screen debug log
Last active August 25, 2022 13:03
UE4 Screen debug log
//Pars: id, seconds, color, text
GEngine->AddOnScreenDebugMessage(0, 1, FColor::Red, TEXT("HI"));
GEngine->AddOnScreenDebugMessage(76867, 3, FColor::MakeRandomColor(), FString::FromInt(8572));
GEngine->AddOnScreenDebugMessage(76867, 5, FColor::MakeRandomColor(), FString::SanitizeFloat(3.141592f));
@sephirot47
sephirot47 / UE4 Load Texture
Created June 17, 2015 20:54
UE4 Load Texture
//En el constructor (no el BeginPlay)
UTexture2D *texture;
static ConstructorHelpers::FObjectFinder<UTexture2D> Texture(TEXT("/Game/StarterContent/Textures/T_Spark_Core.T_Spark_Core"));
texture = Texture.Object;
@sephirot47
sephirot47 / UE4 Get Player Controller of an Actor
Created June 18, 2015 15:31
UE4 Get Player Controller of an Actor
UGameplayStatics::GetPlayerController(actor, 0)
@sephirot47
sephirot47 / UE4 World to screen point
Created June 18, 2015 15:32
UE4 World to screen point
//From the actor's viewport (camera)
FVector2D result;
UGameplayStatics::GetPlayerController(actor, 0)->ProjectWorldLocationToScreen(pointInWorld, result);
//result now has the screen point(x,y)
@sephirot47
sephirot47 / UE4 Bind Action
Last active August 29, 2015 14:23
UE4 Bind Action
character->InputComponent->BindAction("Jump", IE_Pressed, this, &AMyCharacter::HandleJump);
character->InputComponent->BindAction("Jump", IE_Released, this, &AMyCharacter::HandleJump);