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).
The Error: error : In BZGame_GameObjectInterface: 'Member variable declaration' is not allowed here
How can I workaround this?
asked Dec 21 '14 at 10:57 PM in C++ Programming
You can make a virtual getter in your interface
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!
Follow this question
Once you sign in you will be able to subscribe for any updates here