Posts

Showing posts from July, 2022

Open Level

Unreal void APlayerChar::SwitchLevel() { class UGameplayStatics::OpenLevel(this, TEXT("NewLevel")); }//#include "Kismet/GameplayStatics.h"  Unity void SwitchLevel() => SceneManager.LoadScene(1);//using UnityEngine.SceneManagement; 

UI & Widgets

 Unreal virtual void NativeConstruct() override; bool UTestWidget::Initialize() { MyTextBlock_Name->SetText(FText::FromName("Player"));//UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) class UTextBlock* MyTextBlock_Name;                  return true; } void UTestWidget::NativeConstruct() { MyButton->OnClicked.AddDynamic(this, &UTestWidget::GamePause);//UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) class UButton* MyButton_Pause;                  if(EnemyRange < 100) MyTextBlock_String->SetText(FText::FromName("Alert! : Enemy Near, You"));//UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) class UTextBlock* MyTextBlock_String; } void UTestWidget::GamePause() { class UGameplayStatics::SetGamePaused(GetWorld(), true); } //AMyHUD.h with #include "GameFramework/HUD.h"  UPROPERTY(EditDefaultsOnly) TSubclassOf<class UUserWidget>  theTestWidget; void AMyHUD::PortWidget() {                                  UTestWidget* theTestWidge

Animation

 Unreal void UMy_AnimInstance::NativeInitializeAnimation() {   if (theActorPawn == nullptr) theActorPawn = TryGetPawnOwner();//UPROPERTY() APawn* theActorPawn; if (IsValid(theActorPawn)) thePawnMomnt_Framwork = theActorPawn->GetMovementComponent();  } void UMy_AnimInstance::NativeUpdateAnimation(float DeltaSecond) { if (thePawnMomnt_Framwork && theActorPawn) {//UPROPERTY() UPawnMovementComponent* thePawnMomnt_Framwork; plyrMovmntSpeed = theActorPawn->GetVelocity().Size();UPROPERTY(BlueprintReadOnly) float plyrMovmntSpeed;                                 plyrIsJump = thePawnMomnt_Framwork->IsFalling();////UPROPERTY(BlueprintReadOnly) bool plyrIsJump;                 //UPROPERTY() AMyPlayerChar* thePlyrClass; if ((thePlyrClass = Cast<AMyPlayerChar>(theActorPawn)) != nullptr)  plyrCrouch = thePlyrClass->isCrouch;//UPROPERTY(BlueprintReadOnly) bool plyrCrouch; } Unity     Animator anim;     void Start() => anim = GetComponentInChildren<Animator

Navigation Mesh

 Unreal void APlayerChar::Tick(float DeltaTime) { Super::Tick(DeltaTime);         AActor* thePlyr; UNavigationSystem::SimpleMoveToActor(GetController(), thePlyr); } Unity NavMeshAgent agnt; private void Update() => agnt.SetDestination(thePlyr.transform.position);

Play Sound

 Unreal void AGameActor::PlaySoundEffect() {                 USoundBase* theSoundFX; class UGameplayStatics::PlaySoundAtLocation(this, theSoundFX, GetActorLocation());//#include "Sound/SoundBase.h" } Unity void AGameActor::PlaySoundEffect() {        AudioSource* theSoundFX = GetComponent<AudioSource>();//audioSource.PlayOneShot(audioClip, 0.7f);        theSoundFX.Play(); }

Spawn Particles

 Unreal void AGameActor::PlayParticleEffect() {                 UParticleSystem* theParticleFX; class UGameplayStatics::SpawnEmitterAtLocation(this, theParticleFX, GetActorLocation());//#include "Particles/ParticleSystem.h" } Unity void PlayParticleEffect() {         ParticleSystem theParticleFX = GetComponent<ParticleSystem>();         theParticleFX.Play(); }

Tag

 Unreal void APlayerChar::NotifyActorBeginOverlap(AActor* OtherActor) { Super::NotifyActorBeginOverlap(OtherActor);                 if(GetCapsuleComponet->ComponentHasTag("OtherComp")) UE_LOG(LogTemp, Display, TEXT("OtherComp has Overlap the Player Capsule")); } Unity Override void OnTriggerEnter(Collider other) => if (other.gameObject.CompareTag("OtherObj")) Debug.Log("the Player Capsule has Trigger OtherObj");

Spawn

 Unreal UPROPERTY() AActor* theActor; FActorSpawnParameters SpawnParameter; void APlayerChar::BeginPlay() { Super::BeginPlay();     AActor* SpawnActor = GetWorld()->SpawnActor<AActor>(theActor, GetActorLocation(), GetActorRotation(), SpawnParameter); } Unity public GameObject theGameObject; void Update() => Instantiate(theGameObject, transform.position, Quantanion.identity);

Function on time duration

  Unreal void ATestActor::BeginPlay(){ Super::BeginPlay(); GetWorld()->GetTimerManager().SetTimer(functionDelay, this, &ATestActor::theFunction, delayTime, delayLoop); } void ATestActor::Tick(float DeltaTime) { Super::Tick(DeltaTime); if(stopFtimHandlr) GetWorld()->GetTimerManager().ClearAllTimersForObject(this);//GetWorld()->GetTimerManager().ClearTimer(functionDelay); } void ATestActor::theFunction(){ UE_LOG(LogTemp, Display, TEXT("Function work on Particular time period")); } Unity public float delayTime; public float delayLoopTime; [SerializeField] bool stopInvoke; void Start() => InvokeRepeating("theFunction", delayTime, delayLoopTime); private void Update() => if(stopInvoke) CancelInvoke(); void theFunction() => print("Function work on Particular time period");

Ray Tracing

 Unreal void APlayerChar::Tick(float DeltaTime) { Super::Tick(DeltaTime); FHitResult* Outhit; float traceLimit = 100;                 if(GetWorld()->LineTraceSingleByChannel(Outhit, GetComponentLocation(), GetForwardVector() * traceLimit, ECC_Visiblity)) { UE_LOG(LogTemp, Display, TEXT("%s"), *hitOut->GetName());                     DrawDebugLine(GetWorld(),  GetComponentLocation(), GetForwardVector() * traceLimit, FColor::Red, false, 1, 0, 5);//#include "DrawDebugHelpers.h"                 } } Unity void Update() {         RaycastHit hit;         float rayLimit = 100;         if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, rayLimit))  { Debug.Log(hit.collider.gameObject.name);             Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.red);          } }

Hit Trigger

 Unreal APlayerChar::APlayerChar() { OnComponentBeginOverlap.AddDynamic(this, &APlayerChar::OnCompHit); }//if not working the AddDynamic Function delegate use on BeginPlay() void APlayerChar::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) { //CurrentJumpCount = 0;  GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("I Hit: %s"), *OtherComp->GetName()));                  if(OtherComp.ComponentHasTag("theComponent")) UE_LOG(LogTemp, Warning, TEXT("Overlap theComponent")); } Unity [SerializeField] string colliderName; void OnTriggerEnter(Collider collider) => colliderName = collider.gameObject.name;

Hit Any Collider

Unreal APlayerChar::APlayerChar() { GetCapsuleComponent()->OnComponentHit.AddDynamic(this, &APlayerChar::OnCompHit); }//if not working the AddDynamic Function delegate use on BeginPlay()  void APlayerChar::OnCompHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) { //CurrentJumpCount = 0;                  if(OtherComp != this && OtherComp != NULL) UE_LOG(LogTemp, Warning, TEXT("Collision On Component")); GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("I Hit: %s"), *OtherComp->GetName())); } Unity [SerializeField] string collisioName; void OnCollisionEnter(Collision collision) => collisioName = collision.gameObject.name; private void OnGUI() => GUI.Label(new Rect(10, 10, 100, 20), "collision Name = " + collisioName);

Variables On Log

Unreal                 FString MyStringValue = "String";             UE_LOG(LogTemp, Display, TEXT("FString value is: %s"),  *MyStringValue);                 bool MyBoolValue = true; UE_LOG(LogTemp, Display, TEXT("bool value is: %s"),  MyBoolValue? "true" : "false");                 float MyFloatValue = 8; UE_LOG(LogTemp, Display, TEXT("float value is: %f"),  MyFloatValue);                 int MyIntValue = 3; UE_LOG(LogTemp, Display, TEXT("Integer value is: %i"),  MyIntValue); Unity var boolValue = true; var floatValue = 8; var intValue = 3; Debug.Log("bool value is: " + boolValue + "\n" + "float value is: " + floatValue + "\n" + "Integer value is: " + intValue);

If Press AnyKey

 Unreal void APlayerChar::Tick(float DeltaTime) { Super::Tick(DeltaTime); APlayerController* plyrCntrlr = GetWorld()->GetFirstPlayerController(); if(plyrCntrlr->WasInputKeyJustPressed(EKeys::AnyKey)) GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Cyan, TEXT("Key pressed"));//need #include "Engine/GameEngine.h" } Unity bool pressKey; void Update() => pressKey = Input.anyKey | Input.GetKey(KeyCode.E); void OnGUI() { if(pressKey)  GUI.Label(new Rect(10, 10, 100, 20), "Hello World!"); }

Player Movement Input

Unreal void APlayerChar::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) { PlayerInputComponent->BindAxis("MoveForward", this, &APlayerChar::MoveForward); PlayerInputComponent->BindAxis("MoveRight", this, &APlayerChar::MoveRight); } void MoveForward(float Value) { Move(Value, EAxis::X);} void MoveRight(float Value) { Move(Value, EAxis::Y);} void Move(float DirValue, EAxis::Type Axis){                 if(ThirdPerson) {                 const FRotator YawRotation(0, Controller->GetControlRotation().Yaw, 0);//#include "GameFramework/Controller.h"                  const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(Axis);                 AddMovementInput(Direction, DirValue);                 } else if(SecondPerson) {}                 else if(FristPerson) { AddMovementInput(GetActorForwardVector(), DirValue); }                 else if(TopDown) {}                 else if(SideScroll) {} } Unity void

Find Component

Unreal   APlayerChar::APlayerChar() {   // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true;                 //UStaticMeshComponent* ObstacleMesh = Cast<UStaticMeshComponent>(GetDefaultSubobjectByName(TEXT("Obstacle Mesh")));//Remember : Name was match with Blueprint otherwise crash ue4 //but Error When Use this Function like ObstacleMesh->SetHiddenInGame(true);                 USkeletalMeshComponent* PlayerMesh = GetPawn()->FindComponentByClass<USkeletalMeshComponent>();                 UCapsuleComponent* plyrCapsul = this->GetCapsuleComponent(); } Unity [SerializeField] CapsuleCollider plyrCapsul; void Start() => plyrCapsul = this.gameObject.GetComponent<CapsuleCollider>();

Select Asset from Folder

 Unreal AMyGameGameModeBase::AMyGameGameModeBase() { static ConstructorHelpers::FObjectFinder<USkeletalMesh> PlayerMesh(TEXT("/Game/MyContent/Get/thePlayer3DModel.thePlayer3DModel"));//D:\GamEngine\UnrelEngine\Projects\4.25\MyGame\Content\MyContent\Get\thePlayer3DModel.fbx if (PlayerMesh.Succeeded()) this->GetPawn()->FindComponentByClass<USkeletalMeshComponent>()->SetSkeletalMesh(SetPlayerMesh.Object); } Unity     public GameObject playerMesh;     //[MenuItem("AssetDatabase/AddMesh")]//using UnityEditor;     //static void ObjectFind() { var playerMesh = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/MyContent/Get/thePlayer3DModel.fbx", typeof(GameObject));//D:\Game_-Devlopment\Game-Engine\Unity\Project\MyGame\Assets\MyContent\Get\thePlayer3DModel.fbx                   //GameObject loadMesh = playerMesh; }

Auto Move

 Unreal void APlayerChar::Tick(float DeltaTime) { Super::Tick(DeltaTime); FVector movLoctn = GetActorLocation(); movLoctn.X += 8;//(+=) because FVector::X already declare, You Only Add Speed which is '8' SetActorLocation(movLoctn); } Unity private void Update() => transform.Translate(Vector3.forward * 8 * Time.deltaTime);