Property size mismatch

I’m following along in the book ‘Building an RPG with Unreal’ and have hit what appears to be a bug when attempting to add a C++ class. The steps can be reproduced by doing the following:

  1. Create a basic C++ project
  2. Add a C++ Class based on Actor called Controllable Character
  3. Replace the .h with the .h below
  4. Replace the .cpp with the .cpp below
  5. Compile in UE, receive error (pic 1)
  6. Close and re-open UE, class is gone

Alternatively:

  1. Add class to scene, close and re-open UE, receive crash report dialog (pic 2)

ControllableCharacter.h:

#pragma once

#include "Object.h"
#include "ControllableCharacter.generated.h"

UINTERFACE()
class RPG_API UControllableCharacter : public UInterface
{
  GENERATED_UINTERFACE_BODY()
};

class RPG_API IControllableCharacter
{
  GENERATED_IINTERFACE_BODY()

  virtual void MoveVertical( float Value );
  virtual void MoveHorizontal( float Value );
};

ControllableCharacter.cpp:

#include "RPG.h"
#include "ControllableCharacter.h"

UControllableCharacter::UControllableCharacter( const class FObjectInitializer& ObjectInitializer )
  : Super( ObjectInitializer )
{
}

void IControllableCharacter::MoveVertical( float Value )
{
}

void IControllableCharacter::MoveHorizontal( float Value )
{
}

Pic 1:

83255-untitled1.png

Pic 2:

This is my second time writing this up, the first time after clicking on ‘Ask Your Question’ it brought me back to a blank question. Hopefully it works this time.

Edit: Hurray it posted!! On the downside, after adding a link to this post in the crash report and submitting I realized that my project is entirely unable to open in UE Editor now due to this issue, it just crashes every single time.

hey -

I want to confirm if it is intentional that you created a class based on actor and then changed it to inherit from UInterface? I’m also not sure how you’re adding the class to the level after your changes since after the changes the class is an interface rather than an actor which cannot be placed in the level.

If you are trying to use an interface in code, it may help to the tutorial for interfaces that was created by another community member:

Cheers

Hey - I’m mainly just following along in the book ‘Building an RPG with Unreal’, and that was what he said to do. Could be that it’s just bad practice what he’s suggesting:

So firstly, we will look into the interface. We'll start by creating a new class derived from an Actor, just as we did in the previous chapter. Name it as ControllableCharacter.

After Unreal generates the code files, open up ControllableCharacter.h, and change it to the following code:

I did manage to revive the project by compiling it in VS 2015, but until then the editor wouldn’t even load. I did also get the editor loading by removing binaries and re-generating the project.

I’m glad to hear you were able to get access to the project back. Rather than creating a class that inherits from Actor and turning it into a an UInterface class, it will probably work best for you to create the class based on UObject or with no default inheritance (inherit from None if created inside the editor). The wiki page I linked previously is another good tool for using code based interfaces as well.

Cheers

Thanks , that does appear to work much better. I have submitted the issue as Errata to the book, with a link to this post.