Hello, good day! Recently, I have started tinkering with Unreal Engine 4.12 and C++. It is very exciting indeed! For your discretion I started learning the engine and C++ about 5 days now so don’t expect too much. I apologize if there are things I might have done wrong.
I did my research about this but did not find the most appropriate answer to my question (or maybe the problem is just me).
Let me just give a quick run through what I want to do:
1.) I want to create a class named ItemManager.
2.) This class will have 2 integer arguments in its constructor: (int itemID) (int itemType)
3.) I created a C++ class in Unreal Engine and set Actor as its parents class. Note: This class as an actor because this will also have its own static mesh and texture materials which will be used when this item will be spawned in the World. What I’m thinking is if an item is dropped on the ground, it will use that static mesh to display how it would look - well - when it’s on the ground. (For some reason I do not prefer an item looking exactly how it looks when spawned in the world. Moving on…)
4.) In ItemManager.h I have this:
#pragma once
#include "GameFramework/Actor.h"
#include "ItemManager.generated.h"
UCLASS(Blueprintable)
class MYPROJECT_API AItemManager : public AActor
{
GENERATED_BODY()
public:
//For some reason it requires this I don't know why
AItemManager(const FObjectInitializer& ObjectInitializer);
// Construct that I want
AItemManager(int, int);
// Item Manager Properties
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Item Properties")
int itemID;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Item Properties")
int itemType;
UFUNCTION(BlueprintCallable, Category = "Item Manager Methods")
int getItemID();
};
5 .) In my ItemManager.cpp is this:
#include "MyProject.h"
#include "ItemManager.h"
//For some reason it requires this I don't know why
AItemManager::AItemManager(const FObjectInitializer& ObjectInitializer): Super(ObjectInitializer){}
//Overload constructor
AItemManager::AItemManager(int x, int y)
{
itemID = x;
itemType = y;
}
int AItemManager::getItemID() {
return itemID;
}
6 .) It compiles well and the class shows up in Unreal Engine.
7 .) Now the real question is, how will I be able to use this in my blueprints? I tried Cast to I’m not sure what that does.
I have a different person (also learning) working on picking up the item from the ground and sending them to the inventory. We are using begin overlap, what I want to know is How to incorporate a C++ class in Visual Scripting.
Thank you so much!