How do I make a USTRUCT?

Hello,

I try to make a simple USTRUCT in C++, that has two properties, one Actor, and a FName:

This is my WeaponSlot.h

#pragma once

#include “Weapon.h”
#include “WeaponSlot.generated.h”

USTRUCT()
struct FWeaponSlot
{
  GENERATED_USTRUCT_BODY()

  UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=WeaponSlot)
  FName socketName;

  UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = WeaponSlot)
  AWeapon* weapon;

 };

AWeapon is just an Class derived from ACtor, that I did not touch yet.

#pragma once

#include "Item.h"
#include "Weapon.generated.h"

/**
 * 
 */
UCLASS()
class SLAVES_API AWeapon : public AItem
{
	GENERATED_UCLASS_BODY()

	
	
};

I try to use my struct inside my own Component:

#pragma once

#include "Weapon.h"
#include "WeaponSlot.h"
#include "Components/ActorComponent.h"
#include "WeaponControllComponent.generated.h"

UCLASS(meta = (BlueprintSpawnableComponent))
class SLAVES_API UWeaponControllComponent : public UActorComponent
{
	GENERATED_UCLASS_BODY()

	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = WeaponControll)
	TArray<FWeaponSlot> weaponSlots;

	UFUNCTION(BlueprintCallable, Category = WeaponControll)
	void FireAllWeapons();
};

Here is the error oputput I get (sorry only in german :()

1>------ Erstellen gestartet: Projekt: Slaves, Konfiguration: DebugGame_Editor x64 ------
1>  Performing 2 actions (max 4 parallel jobs)
1>  Slaves.generated.cpp
1>D:\dev\Unreal Projects\Slaves\Intermediate\Build\Win64\Inc\Slaves\Slaves.generated.cpp(118): error C2039: 'Weapon': Ist kein Element von 'FWeaponSlot'
1>          D:\dev\Unreal Projects\Slaves\Source\Slaves\WeaponSlot.h(9): Siehe Deklaration von 'FWeaponSlot'
1>D:\dev\Unreal Projects\Slaves\Intermediate\Build\Win64\Inc\Slaves\Slaves.generated.cpp(118): error C2661: 'UObjectProperty::UObjectProperty': Keine überladene Funktion akzeptiert 4 Argumente
1>D:\dev\Unreal Projects\Slaves\Intermediate\Build\Win64\Inc\Slaves\Slaves.generated.cpp(119): error C2039: 'SocketName': Ist kein Element von 'FWeaponSlot'
1>          D:\dev\Unreal Projects\Slaves\Source\Slaves\WeaponSlot.h(9): Siehe Deklaration von 'FWeaponSlot'
1>D:\dev\Unreal Projects\Slaves\Intermediate\Build\Win64\Inc\Slaves\Slaves.generated.cpp(119): error C2661: 'UNameProperty::UNameProperty': Keine überladene Funktion akzeptiert 3 Argumente
1>  -------- End Detailed Actions Stats -----------------------------------------------------------
1>ERROR : UBT error : Failed to produce item: D:\dev\Unreal Projects\Slaves\Binaries\Win64\UE4Editor-Slaves-Win64-DebugGame.pdb
1>  Cumulative action seconds (8 processors): 0,00 building projects, 0,12 compiling, 0,00 creating app bundles, 0,00 generating debug info, 0,00 linking, 0,00 other
1>  UBT execution time: 4,34 seconds
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets(38,5): error MSB3073: Der Befehl ""D:\dev\Unreal Engine 4\Unreal Engine\4.3\Engine\Build\BatchFiles\Build.bat" SlavesEditor Win64 DebugGame "D:\dev\Unreal Projects\Slaves\Slaves.uproject" -rocket" wurde mit dem Code -1 beendet.
========== Erstellen: 0 erfolgreich, 1 fehlerhaft, 0 aktuell, 0 übersprungen ==========

It makes no sense to me, maybe someone can help?

It would seem like it’s happening in code that you’re not showing us (the error line numbers are in the hundreds). Hard to tell without seeing the bad code, but could it be something with the case? You declared in your struct AWeapon* weapon;, and the error report is showing capitalized 'Weapon'.

The Error happens inside the generated File of my Game Module. Since it is generated, I cant really edit it anyway to fix any error? I saw that ‘case’ problem, which is weird. Do I have to name my struct properties after a certain Scheme?

Try to add this USTUCT(BlueprintType) in your struct coz this allow you to use struct as variable in blueprint, maybe that coz the error ?

Lies mal genau den Error Log. Anfang steht, dein Struct hätte keine Variable namens “Weapon”. Das stimmt auch. Sie heißt “weapon”. Irgendwo hast du dein Struct genutzt und wohl die Variablen falsch geschrieben. Das gleiche mit “SocketName”. Es heißt in deinem Struct aber “socketName”. Dann meckert er noch wegen 2 überladenen Funktionen rum. Schau mal nach welche er meint. Die müsste eigentlich rot unterstrichen sein, wenn die Falsch sind.
Meist hast du da mehr oder weniger Paramter übergeben, als vorgesehen waren.

Read your log again. At the beginning it say that your struct doesnt contain a variable named “Weapon”. And thats right, it’s called “weapon”. Somewhere in your project you used your Struct and typed the variable name wrong. Same goes for the “SocketName”. It’s called “socketName” in your struct. And furthermore, the log says that you have 2 overload functions. Look for the functions he meant. They should be underlined in red if they are used wrong. Most of the time you used more or less paramter for the function and not the count that was provided.

(:

Will try that when I am home. Thanks.

Die einzige Stelle in der ich das Struct verwende, ist in UWeaponControllComponent, bei der Deklaration der Variable. Die Fehlermeldung kommt aus der Slaves.generated.cpp, was wiedderum mein GameModule ist. Ich greif nirgendwo auf properties von dem Struct zu. Ich benutze das nichtmal irgendwie :frowning: Hab quasi nur die Klassen so wie ich sie weiter oben gepostet habe und bekomme schon den Fehler.

Ehm, setz mal bitte im Struct, in deinen UPROPERTY Sachen die Category Namen in " " Anführungszeichen. Nur um sicher zu gehen, dass das keinen Fehler hervorruft. Weil da hab ich irgendwas im Hinterkopf.

EDIT: Wobei ich das beides im Code hab. Kann es auch nicht sein. Mach es trotzdem mal. Ansonsten wäre das “BlueprintType” hinter USTRUCT noch ein Versuch wert, aber das wurde dir weiter oben ja schon vorgeschlagen.
Diese Fehlerlogs lassen so viel Möglichkeiten offen für Fehler… Epic könnte die Fehlermeldungen mal etwas überarbeiten.

This did not work.

However, when I remove the UPROPERTY Macros from the structs properties, it compiles…

Ok this is weird. I changed the names of my properties to uppercase, now it compiles. This is so weird for me. Do I have to have uppercased variable names in Structs for them to work? oO

i have no idea also, normally i put all my variable’s first letter to uppercase, maybe something to do with Unreal Build Tool.

For the same scenario, I now got it to work. However, on my WeaponSlot Struct inside the WaeponControll Component, I cant set the Weapon Actor. Even if I select One in the components Window of my Character, it wont keep the selection. The UPROPERTY Settings for my Weapn Member of WeaponSlot are set to EditAnywhere, BlueprintReadWrite

In the Log Window it says the following when I try to Assign my Weapon:

LogProperty:Warning: Illegal TEXT reference to a private object in external package (BP_Weapon_C /Game/Maps/Example_Map.Example_Map:PersistentLevel.BP_Weapon_4) from referencer (WeaponControllComponent /Game/MixamoAnimPack/MixamoCharacter_Master.MixamoCharacter_Master_C:WeaponControllComponent_0). Import failed…

Unfortunately, due to the way FNames work (which is what the UHT uses when parsing those variables), you can sometimes get strange casing issues. We’re working on fixing it!