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. 

C++ Interface: "Member Declation not allowed here".

I would like all of my instanced classes that feature the 'IBZGame_GameObjectInterface' Interface, to have a UPROPERTY Struct that I can edit in all of the blueprints that I make of those classes.

So for example, my struct contains things such as 'build cost', or 'build time', and I want to be able to specify those in every class that has the GameObject interface, and expose the structs variables to Blueprints so that each BP class can have it's own values.

However, when I try to declare a UPROPERTY in the interface class, I get the following compiler error, but I cannot understand why this won't work, or how to work around it? (Note: Removing the UPROPERTY macro allows me to compile, but of course it means this variable won't be exposed to blueprints of classes that have this interface).

 class UBZGame_GameObjectInterface : public UInterface
 class BZGAME_API IBZGame_GameObjectInterface
     /* Return the GameObject Data for use */
     FORCEINLINE FGameObjectData GetGameObjectData() const { return GameObjectData; }
     /* Struct Containing All Relevant Game Object Information, such as Build Times, Resource Costs etc. */
     UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "GameObjectClass")
     FGameObjectData GameObjectData;


The Error: error : In BZGame_GameObjectInterface: 'Member variable declaration' is not allowed here

How can I workaround this?

Product Version: Not Selected
more ▼

asked Dec 21 '14 at 10:57 PM in C++ Programming

avatar image

815 60 97 140

avatar image robbiecooper Dec 30 '14 at 05:13 PM

Hey The Jamsh

Did Rama's solution work? I'm trying to get a very similar thing working, but still getting the error you reported, after using Rama's solution. Cheers

avatar image robbiecooper Dec 31 '14 at 04:02 PM

Hey The Jamsh, I think the struct has to be static. But I don't think you can make a static variable a uproperty...

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

2 answers: sort voted first

A Solution

You can make a virtual getter in your interface

 virtual FYourDataStruct& GetDataStruct() = 0;

Then each class that implements the interface has to provide their stored version of the structure

But the end result is that you can perform logic on the data structure at the interface level, in the .cpp, using GetDataStruct() (even though it is pure virtual in the .h)

That's as uniform as you can make it with an interface + variable data that is common to all extenders of the interface

To re-iterate, you then do the logic on the data structure in the .cpp of the interface itself.

Because the function is returning by reference, you are able to manipulate the data!

Any other class wanting to manipulate the data that is common to the interface can use the function too!



more ▼

answered Dec 22 '14 at 08:08 PM

avatar image

10.6k 446 345 1088

avatar image TheJamsh Dec 23 '14 at 10:43 AM

Thanks Rama! I need to look into this technique more :)

avatar image rob422lou May 18 '15 at 09:45 PM

I can't seem to make this work with blueprints. The function doesn't show up in the editor, and any combination of UFunction with specifiers that tell the blueprint that it can implement the function doesn't compile. Any suggestions?

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

,The Issue is with the UPROPERTY().You need to remove all UPROPERTY() in the interface for you to build

more ▼

answered May 14 '19 at 10:09 PM

avatar image

Ebube Ud
1 1 2

(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