Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

My door doesn't want to open up

Hi everyone, im kinda new to Unreal and I am following a course online that at the moment isnt helpfull. I create a room with a Trigger Volume and a Door. The goal should be to open the door when u enter to the trigger volume. I tried to check the code line by line (2H) and it is perfect. Now Im trying to understand better how function TickCOmponent works because seems that it doesnt trigger at all when I play the game. I tried to put a UE_LOG inside the TickComponent function and nothing print, I thought maybe developer remove the possibility to use EU_LOG in a function called every frame, make sense, so ok. Then I tried to activate these two variable

 PrimaryComponentTick.bCanEverTick = true;
 PrimaryComponentTick.bStartWithTickEnabled = true;

But nothing change Then also tried to insert SetComponentEnabled(true) at the beginning of BeginPlay() but nothing, no way to make it open. I leave my code belove, really hope that someone can help me cause im struggling with this silly stuff for 4-5H. CPP file

 #include "OpenDoor.h"
 #include "Engine/World.h"
 #include "Components/ActorComponent.h"
 // Called when the game starts
 // Sets default values for this component's properties
     PrimaryComponentTick.bCanEverTick = true;    
 void UOpenDoor::BeginPlay()
     Owner = GetOwner();
     ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();

 void UOpenDoor::OpenDoor()
     Owner->SetActorRotation(FRotator(0.f, 0.f, 0.f));    
 // Called every frame
 void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
     Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

     // Poll the trigger volume
     // If the ActorThatOpens is  in the volume        
     if (PressurePlate->IsOverlappingActor(ActorThatOpens))


 #pragma once
 #include "CoreMinimal.h"
 #include "Components/ActorComponent.h"
 #include "Engine/TriggerVolume.h"
 #include "OpenDoor.generated.h"
 UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
 class ESCAPEROOM_API UOpenDoor : public UActorComponent
     // Sets default values for this component's properties
     // Called when the game starts
     virtual void BeginPlay() override;        
     void OpenDoor();
     // Called every frame
     virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
     float OpenAngle = 0.0f;
     ATriggerVolume* PressurePlate;
     AActor* ActorThatOpens; // Remember pawn inherits from actor
     AActor* Owner; // The owning door

Thank you to everyone! An image of the Room with TriggerVolume and the Door

(NB I tried to open the Door in the BeginPlay and it opens super fine) alt text

Product Version: UE 4.19
immagine.png (1.4 MB)
more ▼

asked Jan 20 '19 at 02:59 AM in C++ Programming

avatar image

1 1 2

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Your code seems correct, but I'm starting to think what might be the problem, in your header you state that AActor* Owner; should be the Door right? but in the world outliner your door is just a StaticMesh.

So this is what you need to do:

  1. Create a new blueprint inside the editor (subclassed from Actor) call it something like BP_Door

  2. Add a static mesh component, set the mesh to be the door mesh

  3. Add the OpenDoor component, you can add this since you marked it as BlueprintSpawnableComponent on the header

  4. Place the BP_Door where the door should be (maybe you need to change the rotation of the StaticMeshComponent on it since you want to open the door when rotation is at 0.f, 0.f, 0.f so it would have to be closed on a different rotation?)

  5. Set the trigger volume in your world as the PressurePlate pointer (for this you have to click on the BP_Door on the world, look for the OpenDoor component inside and look at the properties on the right side)

Now your component should be working, on code side it would be wise to check if step 5 wasn't done, usually you would put something like: if (PressurePlate == nullptr) { UE_LOG(LogTemp, Error, TEXT("%s PressurePlate not assigned!"), *GetOwner()->GetName()); return; } on OpenDoor::BeginPlay(), or I think an ensure would be best in this situation.

Hope this helps, keep it up!

more ▼

answered Jan 21 '19 at 02:22 PM

avatar image

346 15 15 25

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question