x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

What are the perks of using [Add Code to Project...]

Up until now I have blindly been adding code to my project with the above menu option, but it occured to me, once i started adding filters to my code in visual studio, that it was clobbering them, even if they had been saved prior or if they were in folders. My question above is, what are the reasons or perks for using this menu option, and when should we be using it. Is it planned to make it so that this menu option doesn't kill my filters?

Loving the toolkit the deeper into the rabbit hole I get.

Product Version: Not Selected
Tags:
more ▼

asked Mar 11 '14 at 02:17 AM in C++ Programming

avatar image

ue4-archive ♦♦ STAFF
50k 3670 1999 9124

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:17 AM +

Ah, and if we use this as a place to start off, if we delete the three files that are generated should we be able to continue to work as long as we remove the other references to the class?

show all comments (comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

This menu option autogenerates a lot of the Unreal template code that you see in the headers and source files. If you just add a new file in Visual Studio it will initially be blank and you will have to copy in (at a minimum) the following:

 // Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.
 
 #pragma once
 
 #include "MyClass.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class AMyClass : public AActor // or whatever else you decide to extend from
 {
     GENERATED_UCLASS_BODY()
 };

for the header and:

 // Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.
 
 #include "MyProject.h"
 
 AMyClass::AMyClass(const class FPostConstructInitializeProperties& PCIP)
     : Super(PCIP)
 {
 
 }

for the class file. Note that all this code (especially the copyright line, found that out the hard way) is required or else your code won't compile. Also, the tool creates all the files like MyClass.generated.h in your Intermediate folder behind the scenes. Using Visual Studio only, you will have to manually regenerate your files (see below).

But yes, the feature is a bit WIP at the moment. For a custom folder/filter, I find it easier to generate them in the main directory first, then migrate them and regenerate all Visual Studio files (right-click your .uproject file and hit "Generate Visual Studio Files"). That usually works without problems.

more ▼

answered Mar 11 '14 at 02:17 AM

avatar image

ue4-archive ♦♦ STAFF
50k 3670 1999 9124

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:17 AM

The copyright notices are not by any means required for the compilation to complete.

Are you saying that, as long as I create two files of this format the generated file will be created at compilation time?

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:17 AM

Really? For me, unless the line is present an error is thrown.

I'm not sure on the second one, having never tried it. To be safe I always manually generate, assuming that because the *.generated.h header does not exist yet compilation will fail.

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:17 AM

I am certain, when you said that i went through and removed all of my header comments and it compiled fine.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Visual Studio filters are generated to exactly match the directory structure on disk and there is currently no way to avoid regenerating project files while using the "Add Code to Project" feature. Generally, you are encouraged to allow project file generation to organize your filters for you but it is not required.

As William mentioned, this feature is not required to add classes to your project. As long as you create a .h and a .cpp file in the same location that the wizard creates them, the generated code (*.generated.h) will be created at compile time, without the need to regenerate vcxproj files at all.

more ▼

answered Mar 11 '14 at 02:17 AM

avatar image

ue4-archive ♦♦ STAFF
50k 3670 1999 9124

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 02:17 AM

Beautiful! I have confirmed that the generated code is created when i drop my own classes in the locations as i wish. No more using the AddCodeToProject option =) Thanks!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question