Non-uobjects limitations

Hi

So, I’m trying to assimilate into UE. Today I’d discovered, that I can’t use dynamic_cast with classes, that don’t derive from UObject. Later on I found out, that I can’t use templates with UObjects.

My question is: what are the limitations for non-unreal classes and what are the limitations for unreal classes?

Thanks in advance

No, you should be able to do so, C++ in UE4 is normal C++ so it should let you do things outside UE4 conventions. Can you paste errors you getting?

Also objects outside UObject are not managed by UE4 garbage collection as well reflection system (you can’t intract with them via Blueprint)

Consider following example:

#include "King.h"
#include "MyClass.h"

class IState
{
public:
    virtual bool Equals( IState* other ) =0;
};

template< class TState >
class State : public IState
{
public:
    virtual bool Equals( IState* other )
    {
        TState* casted = dynamic_cast< TState*>( other ); // problem here
        return Equals( casted );
    };
    
    virtual bool Equals( TState* casted ) =0;
};


class IntState : public State<IntState>
{
public:
    virtual bool Equals( IntState* other )
    {
        return other == this;
    }
};

MyClass::MyClass()
{
    IntState state;
    state.IState::Equals( &state );
}

The error I get is in Casts.h and i says
cannot use dynamic_cast with -fno-rtti

Hi,

Limitations for non-unreal classes:

In general, there is no limitation for it. UE4 use visual studio 2013 compiler. Therefore, if you class compiles in non-UE4 project, it would be compile in UE4 project.
By default, run time type identification is disabled in UE4. If you really need it, just add next string to your project module rules (*.Build.cs).

bUseRTTI = true;

In addition to about uobjects:

You cannot create class derived from two “unreal classes”. Can only inherit from non-UObjects or UInterface derived interfaces.

class AMyCharacter : public ACharacter, public AActor // error
class AMyCharacter : public ACharacter, public NonUObjectClass, public IInterfaceClass // ok

Best regards,

Hey, .

What about mac, same solution? I’ve added truth assignment, but it doesn’t seem to work. The xcode.proj settings’ ‘enable RTTI’ also checked.

Did you enable RTTI in your build script?