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"

The logic of the interface in the classes of successors is not called

I have a base class of weapons that implements the interface: SWeapon From it the class is inherited: SFireWeapon

The problem is that the interface function called in SWeapon is not called in its successor SFireWeapon

Код: SWeapon .h

 #pragma once
 #include "SInteractInterface.h"
 #include "CoreMinimal.h"
 #include "GameFramework/Actor.h"
 #include "SWeapon.generated.h"
 
 UCLASS()
 class SONLINE_API ASWeapon : public AActor, public ISInteractInterface
 {
     GENERATED_BODY()
 
 public:
 UFUNCTION()
     virtual bool Interact_Implementation() override;
 };

SWeapon .cpp

 bool ASWeapon::Interact_Implementation()
 {
     if (GEngine)
     {
         GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, TEXT("WeaponEqip"));
     }
     return true;
 }

SInteractInterface .h

 UINTERFACE(Blueprintable)
 class USInteractInterface : public UInterface
 {
     GENERATED_BODY()
 };
 
 /**
  * 
  */
 class SONLINE_API ISInteractInterface
 {
     GENERATED_BODY()
 
     // Add interface functions to this class. This is the class that will be inherited to implement this interface.
 public:
 
     UFUNCTION(BlueprintCallable,BlueprintNativeEvent, Category = "Interact")
         bool Interact();
 };

SOnlineCharacter .cpp

 FHitResult HitInteract;
     if (GetWorld()->LineTraceSingleByChannel(HitInteract, TraceStart , TraceEnd, ECC_Visibility, QueryParams))
     {
         AActor* HitActor = HitInteract.GetActor();
 
         ISInteractInterface* InteractInterface = Cast<ISInteractInterface>(HitActor);
 
         if (InteractInterface)
         {
             InteractInterface->Execute_Interact(HitActor);
             DrawDebugLine(GetWorld(), TraceStart, HitInteract.ImpactPoint, FColor::Green, false, 5.0f, 0, 1.0f);
             if (GEngine)
             {
                 GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, TEXT("Interfaceinteract true"));
             }
         }

alt text

alt text

alt text

Product Version: UE 4.18
Tags:
screenshot-1.png (85.7 kB)
screenshot-3.png (390.1 kB)
screenshot-4.png (428.8 kB)
more ▼

asked Mar 11 '18 at 09:32 PM in C++ Programming

avatar image

SVAY
1

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

0 answers: sort voted first
Be the first one to answer this question
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