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"

WidgetComponent won't render in world

Hi everyone, I have created a Widget Component using C++ and attached it to a box trigger by creating it's default sub object in C++ for the Interactive portal I'm doing, the Widget component is supposed to show when ever a player character enters the bounds of the portal, but has shown on the GIF bellow, it is only possible to enable/show the image if I click on any property inside the details panel to redraw the widget...

https://gyazo.com/3b61c222a47249d8c0b2064d43011d99

I followed the answer show in this question: https://answers.unrealengine.com/questions/398335/widgetcomponent-not-visible-when-added-via-c.html, but the problem still persists and it's not shown.

The idea is to show this dpad image, but for some reason it's only showing the white screen and only if I cause a manual redraw by changing a property of the details panel.

https://gyazo.com/873ff6ec7eac72fece38b4eb40dfa0b4

some of the code I'm using is has follows and the main class that contains the Widget Component is a UActorComponent:

This is the BeginPlay of the Component: Super::BeginPlay();

     if (InteractiveWidgetComp)
     {
         UUserWidget* InteractiveWidget = InteractiveWidgetComp->GetUserWidgetObject();
         if (InteractiveWidget)
         {
             UImage* ImgInteractive = Cast<UImage>(InteractiveWidget->GetWidgetFromName("ImgButtonToInteract"));
 
             if (ImgInteractive)
             {
                 InteractiveMaterialInstance = ImgInteractive->GetDynamicMaterial();
             }
         }
     }

And this is the code to actually render the Widget when the player enters the Box Trigger:

 void UInteractableComponent::BeginNotifyInteractive(AActor* InteractiveActor, FVector BeginPosition, FVector EndPosition, int KeyPositionToEnable)
 {
     if (InteractiveActor->IsA(MyPlayerCharacter::StaticClass()))
     {
         MyPlayerCharacter* Player = Cast<MyPlayerCharacter>(InteractiveActor);
         APlayerController* PC = Cast<APlayerController>(Player->GetController());
 
         FVector RelativeInteractiveLocation = FVector(0, 0, 50);
         FRotator RelativeCameraRotation = Player->GetCameraBoom()->GetComponentRotation() + FRotator(0.0f, 90.0f, 0.0f);
 
         if (InteractiveMaterialInstance)
         {
             InteractiveMaterialInstance->SetScalarParameterValue("InteractiveButtonToShow", KeyPositionToEnable);
         }
 
         if (PC)
         {
             InteractiveWidgetComp->SetTwoSided(true);
             InteractiveWidgetComp->SetVisibility(true);
             InteractiveWidgetComp->SetGenerateOverlapEvents(false);
             InteractiveWidgetComp->SetWidgetSpace(EWidgetSpace::World);
             InteractiveWidgetComp->SetDrawSize(FVector2D(50.0f, 50.0f));
             InteractiveWidgetComp->SetOwnerPlayer(PC->GetLocalPlayer());
             InteractiveWidgetComp->SetBlendMode(EWidgetBlendMode::Opaque);
             InteractiveWidgetComp->SetRelativeRotation(RelativeCameraRotation);
             InteractiveWidgetComp->SetRelativeLocation(RelativeInteractiveLocation);
             InteractiveWidgetComp->SetCollisionEnabled(ECollisionEnabled::NoCollision);
             InteractiveWidgetComp->AttachToComponent(Player->GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform);
         }
     }
 }

Update: Hey guys a little update, I have fixed the issue with the D-Pad Image not showing, I had set up the image in the Widget Blueprint has hidden, so it wasn't rendering correctly since I never changed it to visible in code, that has been fixed, but I can't still seem to be able to render it unless I go inside the details and update any property of the actor.

So I also added the request redraw, but it didn't work, it still needs me to manually update anything from the details panel to make it work.

Here are a couple of things that might help pinpoint the problem:

this is the Quickwatch after the request redraw: https://gyazo.com/c94ac5303204e9a876deaf77175dd888

and this is the thing I think is causing the problem: https://gyazo.com/8adb03d4477c4df6de3aedd97de9256c

I don't really understand why it's registering the component two times, once has if it where a child and another has a component when it should only add it has a component.

Product Version: UE 4.20
Tags:
more ▼

asked Aug 12 '18 at 07:39 AM in C++ Programming

avatar image

WolfAlvein
23 13 15 19

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

1 answer: sort voted first

Hey guys, so I was able to finally get this to work, and the way I got it, was to initialize it when I start the BeginNotifyInteractive method on the overlap, So I basically did this:

 if (!IsWidgetInitialized && InteractiveWidgetComp != nullptr && !InteractiveWidgetComp->IsPendingKill())
     {
         InteractiveWidgetComp->SetWidgetClass(InteractiveUserWidget);
 
         UUserWidget* InteractiveWidget = InteractiveWidgetComp->GetUserWidgetObject();
         if (InteractiveWidget != nullptr && !InteractiveWidget->IsPendingKill())
         {
             IsWidgetInitialized = true;
             UImage* ImgInteractive = Cast<UImage>(InteractiveWidget->GetWidgetFromName("ImgButtonToInteract"));
 
             if (ImgInteractive)
             {
                 InteractiveMaterialInstance = ImgInteractive->GetDynamicMaterial();
             }
         }
     }


Basically the problem came because I was trying to instantiate the Widget before the Component had begun play, so by doing this only the first time the player enters the trigger, I make sure that the Component has actually Begun play and it will be able to add the widget correctly.

Thank you and hope this helps someone else.

more ▼

answered Sep 01 '18 at 09:48 AM

avatar image

WolfAlvein
23 13 15 19

(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