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"

Custom Struct == Operator with Array.Find

Hi guys,

I have a little problem with a custom C++ Struct being used in an Array in Blueprints. If I use Array.Find to find an item inside, the overloaded == operator is not called. But if I use my custom Compare Method, written to expose this function to blueprints, it works as expected. Can someone point to my mistake here?

.h

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #pragma once
 
 #include "CoreMinimal.h"
 #include "Engine/UserDefinedStruct.h"
 #include "FSaveStruct.generated.h"
 
 USTRUCT(BlueprintType)
 struct FSaveStruct 
 {
     GENERATED_BODY()
 
 public:
     UPROPERTY(EditAnywhere, BlueprintReadWrite)
     FGuid ObjectUUID;
 
     UPROPERTY(EditAnywhere, BlueprintReadWrite)
     FString UserUUID;
 
     UPROPERTY(EditAnywhere, BlueprintReadWrite)
     int32 ObjectState;
 
     //Constructor
     FSaveStruct()
     {
         UserUUID = "";
         ObjectState = 0;
     }
 
     inline bool operator==(const FSaveStruct& other) const
     {
         GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, "OPERATOR OVERLOADED!");
         return other.ObjectUUID.ToString() == ObjectUUID.ToString() && other.UserUUID == UserUUID;
     }
 };
 
 UCLASS()
 class FANTASYSURVIVAL_API UFSaveStructLib : public UBlueprintFunctionLibrary 
 {
     GENERATED_BODY()
 public:
     UFUNCTION(BlueprintPure, meta = (DisplayName = "Equal FSaveStruct", CompactNodeTitle = "==", Keywords = "== equal"), Category = "Math")
         static bool EqualEqual_FSaveStructFSaveStruct(const FSaveStruct &arg1, const FSaveStruct &arg2);
 };


.cpp:

 #include "FSaveStruct.h"
     
     bool UFSaveStructLib::EqualEqual_FSaveStructFSaveStruct(const FSaveStruct &arg1, const FSaveStruct &arg2)
     {
         return arg1 == arg2;
     }


Blueprint "Code":

I hope someone knows whats wrong here. I need to override the == operator, because I don't want to compare all properties, because the Object State should not be compared (as this is different 99% of times).

Product Version: UE 4.16
Tags:
array_comp.png (101.5 kB)
more ▼

asked Jun 04 '17 at 10:51 AM in C++ Programming

avatar image

Drommedar
26 3 4 8

avatar image HailstoneJosh Jun 04 '17 at 03:38 PM

Can you post the portion that's attached to target on the blueprint that doesn't work?

avatar image Drommedar Jun 04 '17 at 03:47 PM

It's just a replicated array in the Game State. So this should not be the problem to why the operator isn't called, me thinks ;D

attach.png (41.8 kB)
avatar image HailstoneJosh Jun 04 '17 at 03:49 PM

It's possible that the data hasn't replicated yet. Have you put a breakpoint and checked the contents of the array?

avatar image Drommedar Jun 04 '17 at 05:17 PM

Sorry, maybe it wasn't clear. If I do an ForEach Loop over the contents of the array and compare them with the Equals Method, then everything works. So the content is already there, the find method just does not call the overloaded operator.

avatar image SerzaNT Jun 06 '17 at 03:56 PM

Same problem here. I used workaround in the meantime, but i would rly want to know how to get this to work properly.

avatar image Tsaukpaetra Apr 01 '19 at 10:00 PM
  • this. I've been ripping my hair out trying to figure out why blueprints can't find my struct in the TMap, and this seems related. Sigh.

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

1 answer: sort voted first

Have you tried using FORCEINLINE instead of inline? Everything looks okay to me except that - maybe somehow reflection is messing stuff up if your overidden operator isn't [something something weird reflection system magic dragons].

If not that, then what was the output of your debug stuff? Are you seeing the message when the operator runs? (I assume not if you've concluded the operator never fires.)

more ▼

answered Jun 05 '17 at 10:47 PM

avatar image

Teiwaz
639 26 29 57

avatar image Drommedar Jun 08 '17 at 05:01 AM

Will check this when I get back home. But I think I had the FORCEINLINE in already, but we will see ;-D

avatar image NamInUz Feb 02 '19 at 04:38 PM

This doesn't work for me either

(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