x

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"

TriggerBox C++ Problem - Mesh only visible in Editor but not in Game

Greetings everyone! I tried to write a base TriggerBox class includes a StaticMeshComponent. Everything works the way I expected exept that the StaticMesh I include is only visible in the Editor but not when I pressed the play button. Could anyone tell me why this is? I inherit my class from ATriggerBox which is inherit from AActor. So I really don´t see why there is this error.

Here is my .h:

 UCLASS()
 class EMWD_API AMesh_TriggerBox : public ATriggerBox
 {
     GENERATED_BODY()
     
     public:
         AMesh_TriggerBox(const FObjectInitializer& ObjectInitializer);
 
         UFUNCTION(BlueprintCallable, Category = "Debug")
             void Debug(FString Msg);
 
         UFUNCTION(BlueprintCallable, Category = "TriggerEvent")
             virtual void OnOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool FromSweep, const FHitResult& SweepResult);
 
         UFUNCTION(BlueprintCallable, Category = "TriggerEvent")
             virtual void OnEndOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
 
         UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "VisibleMesh")
             UStaticMeshComponent* Visible_Mesh;
        
 };
 


Here is my .cpp:

 AMesh_TriggerBox::AMesh_TriggerBox(const FObjectInitializer& ObjectInitializer)
 {
 
     RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
     Visible_Mesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("Visible_Mesh"));
 
     Visible_Mesh->AttachTo(RootComponent);
 
     ATriggerBox::GetCollisionComponent()->bGenerateOverlapEvents = true;
     ATriggerBox::GetCollisionComponent()->SetRelativeScale3D(FVector(1, 1, 2));
 
     ATriggerBox::GetCollisionComponent()->AttachParent = RootComponent;
     ATriggerBox::GetCollisionComponent()->OnComponentBeginOverlap.AddDynamic(this, &AMesh_TriggerBox::OnOverlap);
     ATriggerBox::GetCollisionComponent()->OnComponentEndOverlap.AddDynamic(this, &AMesh_TriggerBox::OnEndOverlap);
 }
 
 void AMesh_TriggerBox::OnOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool FromSweep, const FHitResult& SweepResult)
 {
 
     Debug("EnterTriggerBox - Chair has been destroyed");
 }
 
 void AMesh_TriggerBox::OnEndOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
 {
 
     Debug("ExitTriggerBox");
 }
 
 void AMesh_TriggerBox::Debug(FString Msg)
 {
     if (GEngine)
     {
         GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Red, Msg);
     }
 }
Product Version: UE 4.9
Tags:
more ▼

asked Sep 28 '15 at 11:51 AM in C++ Programming

avatar image

Epiphanie
1 1 2 2

avatar image Epiphanie Sep 28 '15 at 05:43 PM

Greetings Sean Flint STAFF,

Thanks a lot for your reply! I really didn´t done much more than this. I had just started a new blank project to make some tests because I want to code more in my projects. However, the TriggerBox code was the first one I wrote. I compiled the code and put an instance of it on my map to test it. Everything worked perfect. The event was triggered and I got the debug message but the mesh was invisible. I also checked everywhere in the editor if visible is true. So I have no idea what the problem is. But when you say everything worked when you tried to reproduce my error then it is maybe a bug. I will try to start a new project and re-do it. Maybe it then works for me as well.

By the way. I don´t want do create a blueprint based on the class, The plan was to inherit from this class the final special classes also in code. For example a Switch + Triggerbox combination and stuff like that.

But anyway, I will retry and hope that it work then. Thanks a lot for taking the time to test my code. It is good to know that there is nothing totally wrong with my programming skills.

All the best

Epiphanie

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hello Epiphanie,

I have tried to reproduce your issue, but when I set the static mesh in the Editor I was able to see it both In-Editor and while playing the game. Is there any more information you could provide that could be helpful in attempting to reproduce your issue?

Have you tried to create a blueprint based on the class and set the static mesh through that, or is that not something you're looking to do?

I look forward to hearing back, have a great day,

Sean Flint

more ▼

answered Sep 28 '15 at 02:35 PM

avatar image

Sean L ♦♦ STAFF
43.5k 485 152 442

avatar image Epiphanie Sep 29 '15 at 07:08 AM

I tried it again but it still don´t work. So I made a video of how I do it using the code I posted here. Maybe you could find the error I made? Or is this really a hard bug?

https://youtu.be/Sx0k4S78en4

avatar image Sean L ♦♦ STAFF Sep 29 '15 at 02:04 PM

Hello Epiphanie,

Thank you for creating the video. However, I am a having a bit of trouble seeing the issue. I understand that you're not able to see the mesh, but that was because of your Mesh_Triggerbox Instance settings. Once you turned off the Actor Hidden in Game option, the actor appeared in your game. Was this not what you were trying to achieve? It seemed like once you unchecked that option, your mesh was appearing normally as you wanted it to.

Have a great day,

Sean Flint

avatar image Epiphanie Sep 29 '15 at 04:55 PM

Hallo Sean Flint, The problem is when I set Actor Hidden in Game to false that not only the mesh is visible but also the TriggerBox itself. But the TriggerBox should be invisible and only the Mesh should be visible in game. But I could not find a setting constellation in which this was possible.

All the best Epiphanie

avatar image Sean L ♦♦ STAFF Sep 29 '15 at 05:43 PM

Hello Epiphanie,

I see what the issue was now, I missed it the first time I watched the video. If you'd like, you could zip up your project and upload it to Dropbox or Google Drive and provide a link so that I could take a look and see exactly what is causing the issue, since I have been unable to reproduce it in projects that I have created.

Have a great day,

Sean Flint

avatar image Epiphanie Sep 29 '15 at 07:43 PM

Hello Sean Flint, thanks a lot for that offer. Here is the link: https://www.dropbox.com/sh/8wtbwafn4l9yzg6/AADyjFGwhJqQsCGXICM2iwRna?dl=0

All the best Epiphanie

avatar image Sean L ♦♦ STAFF Sep 29 '15 at 08:41 PM

Hello Epiphanie,

After spending some time looking at your project and looking into the code, I've figured out that you don't want to be using the TriggerBox class as a base for your Mesh_TriggerBox class. That particular class is not really meant to be used in that way. Try creating your Mesh_TriggerBox class in a fresh project and basing it on the Actor class instead of the TriggerBox class. Then, add a collision component to it and use that as your trigger instead, and make sure you add your mesh component. This should allow you to get the result you're looking for.

Have a great day,

Sean Flint

avatar image Epiphanie Sep 30 '15 at 06:48 PM

Thanks again for taking the time to work out my problem. With Actor it actually worked. But from a programmer perspective I can not really see why this is. A TriggerBox is inherited from Actor. So it should have his functionality if it was not overwritten and I could not find the point where this happend. However. It works with Actor and I will go with that. Thanks a lot for your help!

All the best Epiphanie

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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