Advertisement
chevengur

UE5 doesn't see the variable.

Mar 27th, 2024
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | Gaming | 0 0
  1. trigger.cpp
  2.  
  3. // Fill out your copyright notice in the Description page of Project Settings.
  4.  
  5.  
  6. #include "Trigger.h"
  7.  
  8. UTrigger::UTrigger()
  9. {
  10.     // Установите этот компонент на инициализацию при запуске игры и его обновление каждый кадр. Вы можете отключить эти функции
  11.     // для повышения производительности, если они вам не нужны.
  12.     PrimaryComponentTick.bCanEverTick = true;
  13. }
  14.  
  15. void UTrigger::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
  16. {
  17.     Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
  18.  
  19.  
  20.     AActor* Actor = GetAcceptableActor();
  21.     if (Actor != nullptr)
  22.     {
  23.         UE_LOG(LogTemp, Display, TEXT("Unlocking"));
  24.     }
  25.     else
  26.     {
  27.         UE_LOG(LogTemp, Display, TEXT("Relocking"));
  28.     }
  29.  
  30.     UE_LOG(LogTemp, Display, TEXT("Hello, World"));
  31. }
  32.  
  33. AActor* UTrigger::GetAcceptableActor() const
  34. {
  35.     TArray<AActor*> Actors;
  36.     GetOverlappingActors(Actors);
  37.     for (AActor* Actor : Actors)
  38.     {
  39.         if (Actor->ActorHasTag(AcceptableActorTag))
  40.         {
  41.             return Actor;
  42.         }
  43.     }
  44.     return nullptr;
  45. }
  46.  
  47. void UTrigger::BeginPlay()
  48. {
  49.     Super::BeginPlay();
  50. }
  51.  
  52. ***************************************************************************************************************************************
  53.  
  54. trigger.h
  55.  
  56. // Fill out your copyright notice in the Description page of Project Settings.
  57.  
  58. #pragma once
  59.  
  60. #include "CoreMinimal.h"
  61. #include "Components/BoxComponent.h"
  62. #include "Trigger.generated.h"
  63.  
  64. /**
  65.  *
  66.  */
  67. UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
  68. class CRYPTRAIDER_API UTrigger : public UBoxComponent
  69. {
  70.     GENERATED_BODY()
  71.  
  72. public:
  73.     UTrigger();
  74.  
  75. public:
  76.     virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
  77.  
  78. protected:
  79.     // Called when the game starts
  80.     virtual void BeginPlay() override;
  81.  
  82. private:
  83.     UPROPERTY(EditAnywhere)
  84.     FName AcceptableActorTag;
  85.  
  86.     AActor* GetAcceptableActor() const;
  87. };
  88.  
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement