Some questions about how to use C++ classes

  1. How to delete a C++ class ?
  2. How to rename a C++ class ?
  3. How to add a C++ class to a pawn: add like a C++ component to a blueprint pawn ?
  4. How would you set up a custom movement component for a pawn with networking support ?
  1. You can delete a class by deleting the source (files with a .cpp extension), and header (files with a .h extension) files that define and implement the class you want to delete. Keep in mind though that you also have to remove any references to the class you are deleting and any objects of the class you are deleting from the rest of your source code, or your code won’t compile. That includes pointers to objects of your class, classes that inherit from your class, headers included from your class in other classes, etc.

  2. To rename a C++ class you have to
    change the name of the class in the
    source and header files ie.

    class AMyCharacter : public ACharacter
    {
         ...
    }
    

should become

    class ANewName : public ACharacter
    {
         ...
    }

Like deleting a class, renaming a
class involves changing every
reference you have of that class
from the old name to the new name
that you have chosen for it. It would also be a good idea to change the name of your C++ header and source files to match the new name for your class. It isn’t required anymore, but it will make it easier for you to understand what those files are for.

  1. There are multiple ways to include functionality from C++ code in a UE4 pawn. The easiest way from my experience is to first write the base of the class in C++, have that C++ class inherit from APawn, then inherit a blueprint off of the C++ class. This gives your new APawn child all the functionality of APawn, while allowing you to write new functionality for it in the C++ class, and to set up component references (to things such as materials and static meshes) in the blueprint which you inherited off of your C++ class. This allows you to avoid static links in your C++ code, while also giving you the freedom to write much of your code in C++, which can be useful if you want to avoid writing too much code in blueprints or only want to give those using your blueprints access to certain parts of the code. The other way you can include functionality from C++ code in a UE4 pawn is by writing your C++ code to inherit off of UComponent and write your own component logic in C++. This will allow you to include the code as a component in a Blueprint or C++ defined class. Including a custom C++ UComponent should work, but I recommend doing it the way I first described and using inheritance, because I have had issues in the past with custom C++ components.

  2. To set up a custom movement component for a pawn with networking support is not going to be an easy task. You’d have to write your own movement component, inheriting from an existing movement component, and add networking support to it, which believe me, is not going to be easy. If it is possible to use a Character as the basis for what you are doing as opposed to a Pawn, you could always inherit off of UCharacterMovementComponent, which comes with networking support built in. If you must use a Pawn you are going to have to learn how to use networking and replication.

The list formatting wasn’t cooperating, the second 1. and 2. are in response to questions 3. and 4.