Plugin : Initialize protected, persistent object

anonymous_user_a95c0d08
Wed, 15 Nov 2017 15:26:06 +0000
Plugins

Hello,

I’m a Games Engineer student and currently developing a plugin. The plugin will be used through a BPFunctionLibrary.
For the plugin I’ll need an object (let’s call it Watcher), that is created on Plugin StartUpModule() and can be accessed by all classes inside my plugin module. It’s supposed to hold values like position, materials etc.

My first idea was to declare it inside my PluginModule.h and use the StartUpModule() method to create an instance of it. Since the StartUpModule() is called once, Watcher would be a Singleton as intended.

#pragma once

#include "ModuleManager.h"
#include "Watcher.h"

class FEasyFootPrintsModule : public IModuleInterface
{
public:
	 UWatcher* watcher;
	 UWatcher* getWatcher() { return watcher; }

	/** IModuleInterface implementation */
	virtual void StartupModule() override;
	virtual void ShutdownModule() override;
};

Inside the cpp:

void FEasyFootPrintsModule::StartupModule()
{
	watcher = NewObject<UWatcher>();
}

Inside my functions of the BPFunctionLibrary.cpp I’d like to have access to the Watcher object to define different behaviour based on the values inside Watcher. Since Watcher is a member variable of my PluginModule, I need a reference to it. Where do I get it?

Or is there a better solution?

3 posts - 1 participant