UStruct: type must be a UCLASS, USTRUCT or UENUM - unreal-engine4

I’m probably missing something simple but I can’t find it. The struct is marked as USTRUCT() but still it complains about it not being a USTRUCT. It’s not caused by the TArray because removing that still gives the same error. Also I can use the struct FCrusherTrigger in blueprints without a problem at all. But c++ gives me an error.
USTRUCT(BlueprintType)
struct FCrusherTrigger
{
GENERATED_USTRUCT_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CrusherTrigger")
ECollisionShapeEnum CollisionType;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CrusherTrigger")
FTransform RelativeTransform;
FCrusherTrigger()
{
CollisionType = ECollisionShapeEnum::CollisionShape_Box;
}
};
...
// BaseCrusher.h
public:
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "BaseCrusher")
TArray<FCrusherTrigger> TriggersSetup; // <<<<<<<<<<<<< error here ```

Try to place your constructor above your properties, and call it public. My guess, the issue is around your Construct.

Related

#GestureState cannot be used used as an attribute

In a project I want to declare a variable #GestureState, however I get the following error for no reason: "enum 'GestureState' cannot be used as an attribute".
I've worked with this kind of wrapper property before and didn't get this error at the time.
If anyone has an idea where this error might come from, I'll take it.
#GestureState var selected = false // error here :/
This happening because somewhere in the project you're creating an enum named GestureState rename it to something else and you're good to go.
Modify this:
enum GestureState { ... }
To this:
enum GestureStateType { ... }

AngelScript - Avoid implicit default constructor from running

I'm currently testing some simple AngelScript stuff, and noticed something I find a bit strange when it comes to how objects are initialized from classes.
Let's say I define a class like this:
class MyClass {
int i;
MyClass(int i) {
this.i = i;
}
}
I can create an object of this class by doing this:
MyClass obj = MyClass(5);
However it seems I can also create an object by doing this:
MyClass obj;
The problem here is that obj.i becomes a default value as it is undefined.
Additionally, adding a default constructor to my class and a print function call in each one reveals that when I do MyClass obj = MyClass(5); BOTH constructors are called, not just the one with the matching parameter. This seems risky to me, as it could initialize a lot of properties unnecessarily for this "ghost" instance.
I can avoid this double-initialization by using a handle, but this seems more like a work-around rather than a solution:
MyClass# obj = MyClass(5);
So my question sums up to:
Can I require a specific constructor to be called?
Can I prevent a default constructor from running?
What's the proper way to deal with required parameters when creating objects?
Mind that this is purely in the AngelScript script language, completely separate from the C++ code of the host application. The host is from 2010 and is not open-source, and my knowledge of their implementation is very limited, so if the issue lies there, I can't change it.
In order to declare class and send the value you choose to constructor try:
MyClass obj(5);
To prevent using default constructor create it and use:
.
MyClass()
{
abort("Trying to create uninitialized object of type that require init parameters");
}
or
{
exit(1);
}
or
{
assert(1>2,"Trying to create uninitialized object of type that require init parameters");
}
or
{
engine.Exit();
}
in case that any of those is working in you environment.
declaring the constructor as private seems not to work in AS, unlike other languages.

Declaring and using custom attributes in Swift

I would like to be able to annotate my types and methods with meta-data and read those at runtime.
The language reference explains how to declare attribute usages, but is it actually possible to declare your own attributes?
Reading would require some kind of reflection mechanism, which I was not able to find in the reference at all, so the second part of the question probably is - is there reflection possible. If these features are not available in Swift, can they be done with Objective-C code (but on Swift instances and types)?
A relatively unrelated note: The decision of what has been modelled as an attribute and what has been added to the core syntax strikes me as pretty arbitrary. It feels like two different teams worked on the syntax and on some attributes. E.g. they put weak and unowned into the language as modifiers, but made #final and #lazy attributes. I believe that once they actually add access modifiers, they will probably be attributes likes final. Is all of this somehow related to Objective-C interoperability?
If we take the iBook as definitive, there appears to be no developer-facing way of creating arbitrary new attributes in the way you can in Java and .NET. I hope this feature comes in later, but for now, it looks like we're out of luck. If you care about this feature, you should file an enhancement request with Apple (Component: Swift Version: X)
FWIW, there's really not a way to do this in Objective-C either.
You can now do something like this! Check out "Property Wrappers" - https://docs.swift.org/swift-book/LanguageGuide/Properties.html
Here's an example from that page:
#propertyWrapper
struct TwelveOrLess {
private var number = 0
var wrappedValue: Int {
get { return number }
set { number = min(newValue, 12) }
}
}
struct SmallRectangle {
#TwelveOrLess var height: Int
#TwelveOrLess var width: Int
}
var rectangle = SmallRectangle()
print(rectangle.height)
// Prints "0"
rectangle.height = 10
print(rectangle.height)
// Prints "10"
rectangle.height = 24
print(rectangle.height)
// Prints "12"

FluentMongo throwing error all of a sudden

I am using FluentMongo and the MongoDBCSharpDriver. My code was working fine for a while, but after updating my MongoCSharpDriver, I now I keep getting this error when I try to query the database:
"Discriminators can only be registered for classes, not for interface MyLib.Services.IRepoData."
The interface IRepoData is just one that I use for all my objects saved to MongoDB. It just defines _id for everything. Here is the line that is breaking:
var item = Collection.AsQueryable().SingleOrDefault(a => a.Id == itemID);
Can anyone shed some light on this one? If I just use .SingleOrDefault() with no lambda then it works fine, its passing a lambda that breaks it.
EDIT
In case this helps...
var Collection = GetCollection<MyClass>();
private MongoCollection<T> GetCollection<T>() where T : class, new()
{
string typeName = typeof(T).Name;
var collection = db.GetCollection<T>(typeName, safeMode);
return collection;
}
Found it! I was calling GetCollection() from within another generic method, like this:
public T Save<T>(T item) where T : class, IRepoData, new()
{
GetCollection<T>().Save(item);
}
This caused GetCollection to see T as the interface instead of the actual instance class. GetCollection works fine anywhere else.
For anyone else with this problem, I just used a low level query like this instead... Collection.FindOneAs<T>(Query.EQ("Id", itemID.ToString()));

Error "Expected specifier-qualifier-list before" at struct constructor

I am trying to write some code to optimize some Open GL functions for a program I'm writing, unfortunately, I am not exactly a C or C++ veteran, but that's partially why I'm doing this project!
So I'm creating a struct to handle 3x3 matrices and I am defining the struct as follows:
#ifndef MATRIX3BY3_H
#define MATRIX3BY3_H
struct Matrix3by3
{
float ix, jx, kx;
float iy, jy, ky;
float iz, jz, kz;
Matrix3by3() {}
Matrix3by3(const Matrix3by3 &matrix)
{
ix = matrix.ix;
jx = matrix.jx;
kx = matrix.kx;
iy = matrix.iy;
jy = matrix.jy;
ky = matrix.ky;
iz = matrix.iz;
jz = matrix.jz;
kz = matrix.kz;
}
Matrix3by3 (const float _ix, const float _jx, const float _kx,
const float _iy, const float _jy, const float _ky,
const float _iz, const float _jz, const float _kz) :
ix(_ix), jx(_jx), kx(_kx),
iy(_iy), jy(_jy), ky(_ky),
iy(_iz), jx(_jz), kz(_kz) {}
};
#endif
And I get the error (twice)
Expected specifier-qualifier-list
before 'Matrix3by3'
On the line of the first constructor. I have tried to look around for answers for this, and it seems that it has to do with the compiler not knowing that this is a type. So I have tried the following, I'll remove the innards for brevity:
typedef struct Matrix3by3 { ... };
struct Matrix3by3 { struct Matrix3by3() {} ... };
struct Matrix3by3 { ... } Matrix3by3;
typdef struct Matrix3by3;
struct Matrix3by3 { ... };
Which are all solutions that were suggested on blogs and articles that I saw for this error. I also saw that it may arise because of a circular dependency, but this file has no includes that include anything else, and I've even removed them just to be certain from time to time - no change.
I could write this in a objective-c class, I'm sure, but it will probably take a tiny bit more memory and cycles, and that's exactly what I'm trying to avoid. The only thing I can think of left is some compiler/project setting that I have set by default that precludes my using this type of structure. Entirely possible, as I'm learning the language/environment.
Can any one provide some help?
Thanks!
C does not support constructors or member functions of structs. There is no way you will get this to compile as C or Objective-C. You need to compile this as C++ or Objective-C++, at which point it will almost compile: you have an error in your 3rd constructor, in that you're attempting to initialize the members iy and jx multiple times. Once you fix those typos, it compiles just fine.
typedef struct { ... } Matrix3by3;
should work. It declares the anonymous struct as a type.
And use class instead of struct :)
What language/compiler are you translating your program with? I'd guess that you are trying to compile the code as C, while the language features you are trying to use are strictly C++-specific.
The error "Expected specifier-qualifier-list before 'Matrix3by3'" is a GCC-ism and it means that the token "Matrix3by3" is unknown. This is typically the case when you have a type that the compiler doesn't recognize, either because you mistyped it or because you forgot a header. In your case, it's because the type "Matrix3by3" really doesn't exist. You have two options:
Stop using Matrix3by3 directly and start using struct Matrix3by3 instead, as that's the actual type you defined.
Give your struct a typedef. It will look something like
typedef struct {
// fields here
} Matrix3by3