# Plugin : Initialize protected, persistent object

**URL:** <https://forums.unrealengine.com/t/plugin-initialize-protected-persistent-object/409707>\
**Category:** Plugins\
**Tags:** unreal-engine, global, Plugins, CPP, question\
**Created:** [November 15, 2017, 3:26pm UTC](https://forums.unrealengine.com/t/plugin-initialize-protected-persistent-object/409707 "2017-11-15T15:26:06Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [November 15, 2017, 9:29pm UTC](https://forums.unrealengine.com/t/plugin-initialize-protected-persistent-object/409707/2 "2017-11-15T21:29:07Z")

</div>

First of all insted of `UWatcher*` use `WeakObjectPtr<UWatcher>` or else you risking invalid pointer, also read here how to keep this object alive and prevent it from garbage collection:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

As main issue, you eather need to get module class object form module manager:

> **[FModuleManager](https://docs.unrealengine.com/5.1/en-US/API/Runtime/Core/Modules/FModuleManager/)**
>
> Implements the module manager.

Or create singleton in your module class so you can direcly refrence it, you cna look up in other modules in engine to see how it works, here example of HTTP:

[https://github.com/EpicGames/UnrealEngine/blob/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Runtime/Online/HTTP/Private/HttpModule.cpp](https://github.com/EpicGames/UnrealEngine/blob/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Runtime/Online/HTTP/Private/HttpModule.cpp)

[https://github.com/EpicGames/UnrealEngine/blob/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Runtime/Online/HTTP/Public/HttpModule.h](https://github.com/EpicGames/UnrealEngine/blob/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Runtime/Online/HTTP/Public/HttpModule.h)

```
 HTTP_API static FHttpModule& Get();

/** singleton for the module while loaded and available */
static FHttpModule* Singleton;

```

and in CPP

```
FHttpModule& FHttpModule::Get()
{
	if (Singleton == NULL)
	{
		check(IsInGameThread());
		FModuleManager::LoadModuleChecked<FHttpModule>("HTTP");
	}
	check(Singleton != NULL);
	return *Singleton;
}

```

I know you plan to do so with UObject, but i’m not sure if that is safe thing to do, so i recomand you to it with module class as most module classes in engine do.

---

_[View the full topic](https://forums.unrealengine.com/t/plugin-initialize-protected-persistent-object/409707)._
