Visual Studio Snippets
Visual Studio Snippets could be very useful, that’s why I’ve created a public repository with a few examples. Snippets are generated with doxygen style comments.
How to add snippet ?
First of all you have to clone GitHub repository. Then you have two choices:
- Method one. Paste .snippet files into: "C:\Users\$user$\Documents\Visual Studio 2013\Code Snippets\Visual C++\My Code Snippets". Then restart VS.
- Method two. Open Visual Studio, navigate to TOOLS -> Code Snippets Manager… -> Import… (This allows an Add folder option for easier management)
[4.6 Branch and above] Epic seems to have started initial integration with Branch 4.6 and above. Look on GitHub under "\Engine\extras\VisualStudioSnippets" and follow the Readme file.
How to use snippets ?
Import them and just start typing ue4…
After selecting snippet from the list, hit TAB.
To navigate between highlited fields you can use TAB and SHIFT + TAB. After you enter all names, hit ENTER.
Snippets
- ue4classa – Blueprintable class that derives from an AActor. Parameters are: comment, class name and base class name.
/**
* Comment
*/
UCLASS(BlueprintType, Blueprintable)
class AFoo : public AFooBase
{
GENERATED_UCLASS_BODY()
public:
protected:
private:
};
- ue4classu – Blueprintable class that derives from an UObject. Parameters are: comment, class name, base class name.
/**
* Comment
*/
UCLASS(BlueprintType, Blueprintable)
class UFoo : public UFooBase
{
GENERATED_UCLASS_BODY()
public:
protected:
private:
};
- ue4enum – Simple enum. Parameters are: comment, enum name, first member name and it’s comment.
/**
* Comment
*/
UENUM()
enum EMyEnum
{
Name, /**> Comment */
};
- ue4enumdisplay – Enum that can be used with blueprints. Parameters are: comment, enum name, first member name, it’s display name and comment.
/**
* Comment
*/
UENUM()
namespace EMyEnum
{
enum Type
{
Name UMETA(DisplayName = "DisplayName"), /**> Comment */
};
}
- ue4event – This function can be used as an event in blueprint. Parameters are: comment (parameters and return value), UI category, virtual and const modifiers, return type, function name and arguments.
/**
* Comment
* @param Comment
* @return Comment
*/
UFUNCTION(BlueprintImplementableEvent, Category = "MyProject")
virtual void OnFunctionName(args) const;
- ue4func – This function is available for blueprint logic. Parameters are: comment (parameters and return value), UI category, virtual and const modifiers, function name and arguments.
/**
* Comment
* @param Comment
* @return Comment
*/
UFUNCTION(BlueprintCallable, Category = "MyProject")
virtual void FunctionName(args) const;
- ue4interface – Simple ue4 interface. Parmameters are: comment and name.
/**
* Comment
*/
UINTERFACE()
class UFoo : public UInterface
{
GENERATED_UINTERFACE_BODY()
};
class IFoo
{
GENERATED_IINTERFACE_BODY()
};
- ue4log – Simplest log line. Parameters are category, verbosity and message.
UE_LOG(MyProject, Error, TEXT("Log message"));
- ue4logdeclare – Declaration of log category. Place this in main header of your project to allow logging. Parameters are: category, default verbosity and compile time verbosity.
DECLARE_LOG_CATEGORY_EXTERN(MyProject, Log, All);
- ue4logdefine – Definition of log category. Place this in main code file. Parameter is category name.
DEFINE_LOG_CATEGORY(MyProject);
- ue4logfloat – Log line that can be used to print float value. Parameters are: category, verbosity and variable name.
UE_LOG(MyProject, Error, TEXT("The value of 'variable' is: %f"), variable);
- ue4logint – This log line can be used to log an integer value. Parameters are: category, verbosity and variable name.
UE_LOG(MyProject, Error, TEXT("The value of 'variable' is: %i"), variable);
- ue4loguobj – This log line is designed to log from inside of the objects. By default, square brackets contains a name of an object that writes the log. Parameters are: category, verbosity, message and name of a pointer to the object.
UE_LOG(MyProject, Error, TEXT("[%s] Log message"), *(this->GetName()));
- ue4prop – This read/write property is available everywhere (blueprint, instance and archetype details). Parameters are: comment, category, type and name.
/**
* Comment
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyProject")
Type Name;
- ue4struct – Simple structure. Parameters are: comment and name.
/**
* Comment
*/
USTRUCT()
struct FFoo
{
GENERATED_USTRUCT_BODY()
};
- ue4mark – This comment can be used to mark changes made to engine classes. Parameters are: Company symbol, task/ticket number, name and surname of a developer and short description of modification.
/* BEGIN ACME (ACME-938) */
// Name Surname - Comment
virtual void Tick(float DeltaTime);
/* END ACME */
Author: mpo