Hi,
I created a C++ class based on UObject and now I’m trying to create a varaible of this type in a blueprint and call a function on it.
The header looks like this:
#pragma once
#include "UObject/UObject.h"
#include "Greeter.generated.h"
UCLASS(BlueprintType)
class MYPRJ_API UGreeter : public UObject
{
GENERATED_BODY()
public:
UGreeter();
UFUNCTION(BlueprintCallable, Category = Default)
void Greet();
~UGreeter();
};
You mean AActor?
It doesn’t need to be an actor. I won’t be placing it in a level.
I need a C++ type which I can use as a blueprint variable and call functions on it.
Is it correct that UObject is all I need to extend from to get an Unreal-managed object that can be used for the above?
I turns out that instantiating UObject-based classes in blueprint is still not supported in Unreal Engine 4.
So the answer to my question is: It cannot be done at this point.
I don’t think that is correct, i am using a class derived from uobject and I am able to call its functions just fine from blueprint. While instantiating a UObject might not be supported (haven’t checked) from a class variable, you can have an actual object variable and call its functions. If you tried that and it still did not work, I recommend removing the BlueprintType tag and the MYPRJ_API, since those are the only two things you have that are different from mine.
Could you make an instance of the UGreeter a variable (UPROPERTY) of the base class of wherever you want to instantiate it? Lets say in the levelscriptactor, or the gamemode, character class, whatever? I’d have thought you could access that variable from the BP?