Announcement

Collapse
No announcement yet.

Generating headers

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Generating headers

    Hi,
    I tried to follow this https://wiki.unrealengine.com/Interfaces_in_C%2B%2B to create interface etc. It seems to be generated but I can't figure it out how to generate a interface. I can Add some basic code to project trough the editor but not the interface for example.

    #2
    hm I'm successfully working with interfaces... please show some code so that we can help you.

    Basically it's like this:

    Code:
    //this is in 	MyInterface.h
    
    #include "MyInterface.generated.h"
     
    UINTERFACE()
    class UMyInterface : public UInterface
    {
    	GENERATED_UINTERFACE_BODY()
    };
     
    class IMyInterface
    {
    	GENERATED_IINTERFACE_BODY()
     	[function declarations]
    };

    Code:
    //this is in 	MyInterface.cpp
    
    #include "MyInterface.h"
     
    IMyInterface::MyFunction(){}
    // function bodies if needed

    Code:
    //this is in 	SomeClass.h
    
    #include "SomeClass.generated.h"
     
    UCLASS()
    class USomeClass : public UObject, public IMyInterface

    Comment


      #3
      Are you creating classes in visual studio just by adding new classes or UE4 editor to add code to project?

      Header:
      Code:
      // Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.
       
      #pragma once
       
      #include "UDanceInterface.generated.h"
       
      /** Class needed to support InterfaceCast<IToStringInterface>(Object) */
      UINTERFACE(MinimalAPI)
      class UDanceInterface : public UInterface
      {
      	GENERATED_UINTERFACE_BODY()
      };
       
      class IDanceInterface
      {
      	GENERATED_IINTERFACE_BODY()
       
      	virtual FString ToString();
      };
      cpp:
      Code:
      #include "DanceInterface.h"
      
      //////////////////////////////////////////////////////////////////////////
      // ToStringInterface
      
      UDanceInterface::UDanceInterface(const class FPostConstructInitializeProperties& PCIP)
      : Super(PCIP)
      {
      
      }
      
      //This is required for compiling, would also let you know if somehow you called
      //the base event/function rather than the over-rided version
      FString IDanceInterface::ToString()
      {
      	return "IDanceInterface::ToString()";
      }
      And something that uses interface

      Code:
      // Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
      
      #pragma once
      
      #include "DanceCharacter.h"
      #include "DanceInterface.h"
      #include "DanceBot.generated.h"
      
      /**
       * 
       */
      UCLASS()
      class ADanceBot : public ADanceCharacter, public IDanceInterface
      {
      	GENERATED_UCLASS_BODY()
      
      public:
      	virtual FString ToString() OVERRIDE;
      	
      };
      cpp:

      Code:
      // Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
      
      #include "Dance.h"
      #include "DanceBot.h"
      
      
      ADanceBot::ADanceBot(const class FPostConstructInitializeProperties& PCIP)
      	: Super(PCIP)
      {
      
      }
      
      
      //IToStringInterface
      FString ADanceBot::ToString()
      {
      	return "DanceBot!";
      }
      Ok It compiles! But still this generated thing is confusing. Some basic classes can be generated from editor but can't do the same for interface... ?
      Last edited by jmietola; 04-10-2014, 03:11 PM.

      Comment


        #4
        Originally posted by jmietola View Post
        Are you creating classes in visual studio just by adding new classes or UE4 editor to add code to project?

        ...

        Ok It compiles! But still this generated thing is confusing. Some basic classes can be generated from editor but can't do the same for interface... ?
        By now I never used the built in class creation wizard.
        I think it provides only templates for the few most used classes.

        Comment


          #5
          Originally posted by jbjhjm View Post
          By now I never used the built in class creation wizard.
          I think it provides only templates for the few most used classes.
          No it provides templates for every class in your project. There is a checkbox "show all classes".

          Comment


            #6
            Originally posted by maikklein View Post
            No it provides templates for every class in your project. There is a checkbox "show all classes".
            Good to know, thanks!

            Comment

            Working...
            X