Announcement

Collapse
No announcement yet.

Creating a class wtihout FPostConstructInitializeProperties& PCIP?

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

  • replied
    Originally posted by Belven View Post
    'Action' : 'class' type redefinition
    'ActionEnums::ActionType' : 'enum' type redefinition
    The header file is probably getting included more than once. You want this at the top of every .h:
    Code:
    #pragma once
    The file layout of C++ is a little tricky, and UE4 projects can make that more complicated with generated headers. You may want to experiment a bit with a simple Win32 Console Application before writing any serious code.

    Leave a comment:


  • replied
    Complier says no, looks like theres lot's wrong within Action:

    Code:
    namespace ActionEnums
    {
    	enum ActionType
    	{
    		Movement,
    		Combat,
    		Other
    	};
    }
    
    class Action
    {
    public:
    	Action()
    	{
    
    	}
    	ActionEnums::ActionType CurrentActionType;
    };

    Getting these erorrs:

    'Action' : 'class' type redefinition
    'ActionEnums::ActionType' : 'enum' type redefinition
    'CurrentActionType' : undeclared identifier
    'Action' : base class undefined

    Leave a comment:


  • replied
    I wish I had a second pair of eyes around, almost all problems are stupid mistakes, Thanks so much

    Leave a comment:


  • replied
    Your Action() constructor is private, the default access type for a class. Make it public.

    Leave a comment:


  • replied
    New issue I have this within my Bots:

    Action* CurrentAction;

    And I try and assign it within my AIController like so:


    Bot->CurrentAction = new MoveAction();

    Here is MoveAction

    Code:
    #pragma once
    
    #include "Action.h"
    
    class MoveAction : public Action
    {
    public:
    	MoveAction()
    	{
    		CurrentActionType = ActionEnums::Movement;
    	}
    };
    It's giving me this as an error:

    error C2440: '=' : cannot convert from 'MoveAction *' to 'Action *'

    Any Ideas?

    Leave a comment:


  • replied
    Ah ha, I forgot about constructors, didn't realize that it went in here:

    Code:
    class Action 
    {
             Action()
             {
    
             }
    	ActionEnums::ActionType CurrentActionType;	
    };
    You've fixed my problem, thanks

    Leave a comment:


  • replied
    What happens if you put the constructor declaration in the header?
    Action();

    Leave a comment:


  • replied
    Do I still need a .h and .cpp for normal c++ classes?

    I've got this atm as my .h:

    Code:
    namespace ActionEnums
    {
    	enum ActionType
    	{
    		Movement,
    		Combat,
    		Other
    	};
    }
    
    
    class Action 
    {
    	ActionEnums::ActionType CurrentActionType;	
    };
    and this as my .cpp:

    Code:
    #include "The_Battle_of_Maldon.h"
    #include "Action.h"
    
    Action::Action()
    {
    
    }
    doesn't like me doing Action::Action()?

    Leave a comment:


  • replied
    Originally posted by AO View Post
    new isn't going to work for UE4 classes, have you tried replacing new UMoveAction(); with GetWorld()->SpawnActor(...)?

    edit: if it's an UObject you should use something similar to TestObject = NewObject<UPWNTestObject>(this, UPWNTestObject::StaticClass()); instead

    edit2: The answer hub has a bunch of good answers to lots of very specific problems. More info here.
    I've added this to the wiki a while back:
    https://wiki.unrealengine.com/UE3_to...n_Guide#Coding

    Leave a comment:


  • replied
    Thanks, I'll give it ago

    Leave a comment:


  • replied
    You can just create your own plain old C++ classes in Visual Studio.

    Code:
    class FMyCoolClass { .. };
    It's not possible yet to create C++ classes from the Editor yet.

    Leave a comment:


  • replied
    Is is possible to make a normal c++ class instead, I only need something that extends base object anyway?

    Leave a comment:


  • replied
    This issue is that the parameters require FPostConstructInitializeProperties& PCIP, which I have no idea what it is or why I need one.
    Is it possible to not have this in the parameters or if I do need it where do I get PCIP from?

    This required line for UObject declarations...

    Code:
    GENERATED_UCLASS_BODY()
    ... effectively creates some glue that makes your class work with the UObject sub-system. Part of that glue is the declaration of a class constructor, and it is required that you implement it in your module. If your class has a lot of methods, you probably already have a separate .cpp file just for that class, and you can add the constructor definition to that file. If your class doesn't have any code, or all code is inlined, then you can just throw it into any other .cpp file. Typically I use the MyModule.cpp for that, or if I have many classes with no code I add MyModuleClasses.cpp and put the constructors in there (for example, take a look at SettingsClasses.cpp).

    The format for the constructor definition is as follows:

    Code:
    UMyCoolClass::UMyCoolClass( const class FPostConstructInitializeProperties& PCIP )
    	: Super(PCIP)
    {
        /* do object initialization in here, if needed, otherwise leave empty */
    }

    For the creation of UObjects see: UObject Instance Creation
    For the creation of AActors see: Spawning Actors

    Note that UObjects (and therefore AActors as well) have their properties initialized from the INI file, or set to 0/nullptr if no settings are specified. You cannot pass any additional arguments into the constructors but will have to defer all run-time initialization to subsequent method calls or property assignments after creating the object. It seems like a limitation at first, but it opens up some interesting possibilities. For example, all UObjects and actors have the same constructor API, which means that they can be easily created automatically by other means, i.e. from the Blueprint system or when they're replicated over the network. The only thing you have to provide is a class name.

    If custom constructor arguments were allowed then we would have to provide a mechanism to generate constructor calls and populate them with valid arguments automatically at run-time. Probably the only elegant way to do this would be a dependency injection framework, which is quite difficult to create and use in C++. In other similar languages, such as C# this may be a little bit easier, but note that even there most frameworks do not allow custom constructor arguments for serializable objects.
    Last edited by gmpreussner; 04-06-2014, 08:56 PM. Reason: added docs links

    Leave a comment:


  • replied
    So I now have this:

    Code:
    Bot->CurrentAction = NewObject<UMoveAction>(this, UMoveAction::StaticClass());
    but how would I pass in parameters then?

    Leave a comment:


  • replied
    Im not an expert of UE4 yet, but i think you can use this Bot->currentAction = UMoveAction::StaticClass(); ??

    Leave a comment:

Working...
X