How do I use a generated class?

I think I’ve read the documentation through and through, though I might have missed something. And I still can’t seem to find a way to use generated classes properly.

The way I do it is this:

  1. Generate a new class that extends an existing one, from File/Add Code to Project (a really nice feature, by the way)
  2. Switch over to VS
  3. Add properties to the class, using the UPROPERTY macro, etc., just as is done in the pregenerated classes and in the classes they inherit from
  4. Compile

Invariably, I get the “You are not allowed to change generated code” error (though that’s not the precise phrasing). What is the point of generating classes if you can’t use them? Or is the error on my end, in comilation order or assumptions I have that don’t hold true?

An explanation of how to use the code generation feature would be fantastic. If there is one, please link me!

So, I got this working, but it can’t be the right way:

  1. Generate the file in the editor
  2. Turn off VS
  3. Run the shell extension script that generates VS files (otherwise, there is no intellisense in the generated file)
  4. Start VS again
  5. Compile the code in VS
  6. Go to the editor
  7. Compile the code in the editor, and it now functions as intended

Hello Martin!

Compiling in the editor has limitations as to what can be “hot reloaded”. Any changes to the memory layout of your class (such as adding a property) can not be reloaded since instances of that class may be in memory and the memory associated with them has already been allocated. If you add a UPROPERTY to your class, you will need to close the editor and compile in Visual Studio.

Thanks a lot! That clears it up quite well.

I dont know much about the actual editor option of “add code to project”

but if your goal is to create a new class extending an existing one, and adding your own blue print accessible properties:

  1. in your project/source/classes directory create the .h file
  2. in source/private create the .cpp file (copy examples from the ShooterGame download if need be)
  3. compile this code
  4. go into editor and create a new blueprint (works best from an Actor extending class
  5. right click on blue print and “copy reference”
  6. stick this reference in your C++ code where you want to use your new blue printed class :slight_smile:

Easy to follow real example tutorial on this is my Custom HUD Tutorial.

http://forums.epicgames.com/threads/972861-Tutorial-Compile-C-for-UE4-Code-Samples-For-You-(New-Play-Animations-from-C-)?p=31651318&viewfull=1#post31651318

:heart:

Rama

I figured how to do it manually. Thanks for replying thoroughly, though.

The problem I’m having seems specific to generated classes, as the compiler pretty much tells me I can’t modify generated classes. To me, that seems sort of counter to the whole point. That’s why I think I must have missed something.