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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Data Structure of Pointers to Interface Objects

I have an interface that I've created for my creeps:

 #include "CoreMinimal.h"
 #include "ICreepBasic.generated.h"
 UINTERFACE(MinimalAPI)
 class UICreepBasic : public UInterface
 {
     GENERATED_BODY()
 };
 /**
  * 
  */
 class SPAWNCREEPWAVE_API IICreepBasic
 {
     GENERATED_BODY()
 .
 .
 .
 }

Let's say that in one of my other objects I want to store a map.  The key will be the creep type (represented by an int).  The value will be a TArray of the available creeps of that type.  Something like this:

 TMap<int , TArray<IICreepBasic*>> * AvailibleFills;

So if I have 1 creep of type 1 and 2 creeps of type two my structure should look like this:

[1][PointerToCreepOne] ,

[2][PointerToCreepTwo, PointerToCreepThree]

Now, I have a pointer to an IICreepBasic that I want to insert as a type 1 so that I get:

[1][PointerToCreepOne, PointerToCreepFour] ,

[2][PointerToCreepTwo, PointerToCreepThree]

I write a function:

 void AWaypointManager::RegisterCreep(IICreepBasic * TheCreep)
 {
  .
  .
  .
         (AvailibleFills[CreepType])->Add(TheCreep);
     
 
 }

Unfortunately I get this error:

Error C2664: 'RegisterCreep(IICreepBasic *)': cannot convert arguement 1 from TScriptInterface opencarrot IICreepBasic closecarrot ' to 'IICreepBasic *'

I'm not sure where the TScriptInterface is coming into things. Am I missing something obvious?

Product Version: UE 4.17
Tags:
more ▼

asked Sep 25 '17 at 10:27 AM in C++ Programming

avatar image

ManWithBrisk
1 1 2

avatar image ManWithBrisk Sep 26 '17 at 01:48 AM

Having done some more research, I think my problem is related to the idea of a 2D TArray not being supported. I'm going to try wrapping it in a struct per these answers and see if that resolves my issues: https://answers.unrealengine.com/questions/551199/dynamic-2d-array-using-tarray.html https://answers.unrealengine.com/questions/418999/tarray-of-tarray-support-request.html

avatar image ManWithBrisk Sep 26 '17 at 02:54 AM

Hmmm, no luck. There was a problem with my original syntax but now I have an almost identical working function using a struct to wrap the array for a different data type:

CustomStructs.h:

 #pragma once
 
 #include "CreepWaypoint.h"
 
 #include  "CustomStructs.generated.h"
 
 USTRUCT()
 struct FArrayOfWaypoints
 {
     GENERATED_USTRUCT_BODY();
 
 public:
     UPROPERTY()
         TArray<ACreepWaypoint*> WayPointArray;
 }; //ArrayOfWaypoints

WaypointManager.h:

 ...
 TMap<int, FArrayOfWaypoints> * PendingRequests;
 
 UFUNCTION()
     void RegisterRequest(int RequestedType, ACreepWaypoint* RequestingPoint);

WaypointManager.cpp:

 void AWaypointManager::RegisterRequest(int RequestedType, ACreepWaypoint* RequestingPoint)
 {
     if (PendingRequests->Contains(RequestedType))
     {
         ((PendingRequests)->Find(RequestedType))->WayPointArray.Add(RequestingPoint);
     }
     else
     {
         PendingRequests->Add(RequestedType);
         ((PendingRequests)->Find(RequestedType))->WayPointArray.Add(RequestingPoint);
     }
 
 }

That all seems to work. But when I try to setup an identical system to register my IICreepBasic it gives me the same thing about converting from an IIScriptInterface.

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

1 answer: sort voted first

I don't think the issue is the 2D arrays.
You get a compile error where you CALL RegisterCreep, so your type before that doesn't seem to be correct!
Why don't you post how you are calling RegisterCreep() and also, do try to cast it using Cast< IICreepBasic>()

Your TMap should work fine as long as you are actually creating an empty array the first time you add a new KEY. So, actually, you should use
AvailableFills->FindOrAdd(CreepType)->Add(TheCreep) on AvailableFills instead of accessing it like:
(AvailibleFills[CreepType])->Add(TheCreep);

more ▼

answered Sep 26 '17 at 01:25 PM

avatar image

Semitable
77 4 6 11

(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