I’m trying to create a tree-like structure for a very simple dialogue system.
I tried to create it using a USTRUCT that had a pointer to the same struct type and i was kinda succesful with it.
But since i can’t use UPROPERTY or UFUNCTION on a struct with a pointer, i decided to try with UObject instead, so i’d be able to create the tree inside blueprints.
The problem, however, it’s that there seems to be very unstable the object creation.
For example :
DlgRoot = NewObject<UDialogue>();
I’ve also tried this method, but got the same result…
DlgRoot = NewObject<UDialogue>(this, TEXT("DlgRoot"));
When debugging, the DlgRoot will sometimes be valid and sometimes not. And i don’t even have to change anything on the code, simply forcing a recompile(changing something like a variable name) makes it work again.
But even when the object is initialized, i can’t seem to initialize the object variables. I’m probably trying to set them the wrong way…
I’m doing it simply like that :
DlgRoot->Speech = FString(TEXT("Objectest"))
But it’ll always be invalid, regardless of the object existing or not.
I’ve tried to do a similar system a few months ago, and i’ve had the same problems. Basically i had to keep forcing a recompile pretty much everytime because the engine would crash, since the objects weren’t being initialized, even tough there were no errors in the code. But recently, when i tried to go back to this old project to try to guide myself a bit, i realised that if i ever went to a Standalone Game, the objects would ALWAYS not be initialized, always invalid, thus giving me crashes.
So… Whats the proper way to use UObjects , atleast for my purpose?
Also, here’s the code of the object, but there’s not much in it.
UCLASS(BlueprintType, Blueprintable)
class DUALITYGAME_API UDialogue : public UObject
{
GENERATED_BODY()
public:
UDialogue();
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
FString Speech;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
UDialogue* NextSpeech;
};
The constructor wasn’t there by default, i’ve added it just to be sure, but there’s nothing in it… Perhaps that’s the reason?
And the Actor containing the root node.
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
UDialogue* DlgRoot;