How I will be able to create a struct like a blueprint structure in c++ ? I cannot find a working documentation about this topic. I am using 4.7 preview 4.
Are there also any non outdated tutorials in using c++ inside UE4 ?
This a simple struct, it is usable in C++ and in BluePrint and it also has default values suing the CPP macro. The following would be the content of a header called MyTypes.h which you would add to your PreCompiledHeader file.
#pragma once
#include "MyTypes.generated.h"
USTRUCT(BlueprintType)
struct YOURGAME_API FSimpleRange
{
GENERATED_USTRUCT_BODY()
/** Min range value */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Range)
float MinValue;
/** Max range value */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Range)
float MaxValue;
#if CPP
FSimpleRange() :
MinValue(0.f), MaxValue(0.f)
{}
#endif
/** Clamp a range */
float ClampRange(const float Value)
{
return FMath::Clamp(Value, MinValue, FMath::Max(MinValue, MaxValue));
}
};
So what is the PCH stuff all about. Where I would suggest to put all the code for the struct into would be in your main game header, the one that is created automatically and which you will add in most of your cpp files. Of course this greatly depends on the usage of the struct.
If you want to add it into a real PCH file just make sure you have a header file in your Private directory that uses PCH as it’s suffix (Source/Private/MyProjectPCH.h), it will then have to #include the header file where the struct is defined in. One thing to note would be that you are only allowed to include a PCH file into a compilation unit (cpp files).
So is it created out of the studio by using the “Add Code to Project” Button or need I create a fresh class without a parent class inside VS ? What class I generally need to chose ?
A struct is not a class so what I usually do is to create a simple .h file that has that struct in it and I will add the .h to my PreCompiledHeader. I have edited the sample to reflect a full header file.
Hey, Moss, what “PreCompiledHeader” file are you referring to? That’s the part that Rama’s post (which is otherwise great) doesn’t talk about. I get the syntax of structs, I just don’t see any complete explanation of how to add them to your project. Thanks!
hey there Moss I just wanted to thank you because this answer just thought me alot but i don’t know what PreCompiledHeader file you are referring to
and top of that i would actually like to know more about these kind of things regarding the level in which the code is being processed in. like i would really like to be able to create codes i can run inside the editor (not at runtime) being able to access default values and properties of an actor without spawning it etc.
I’m really trying to get my head around the use of USTRUCT right now, and this is the first time I’ve ever come across an example with the section #if CPP and #endif inside the USTRUCT definition. Could someone please elaborate on what these preprocessor directives are accomplishing in this example? Thanks!