# How do I reference variables in different plugin files?

**URL:** <https://forums.unrealengine.com/t/how-do-i-reference-variables-in-different-plugin-files/408580>\
**Category:** Plugins\
**Tags:** Variable, reference, unreal-engine, Plugins, question\
**Created:** [November 2, 2017, 5:00pm UTC](https://forums.unrealengine.com/t/how-do-i-reference-variables-in-different-plugin-files/408580 "2017-11-02T17:00:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kochab](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kochab](https://forums.unrealengine.com/u/Kochab)\
**Post date:** [November 2, 2017, 5:00pm UTC](https://forums.unrealengine.com/t/how-do-i-reference-variables-in-different-plugin-files/408580/1 "2017-11-02T17:00:12Z")

</div>

I have `Plugin.cpp`. There are variables in `Plugin.cpp` that `PluginComponent.cpp` needs. All files reside in the same plugin folder. How do I do that?

---

<div class="post-metadata">

**Author:** ![Kochab](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kochab](https://forums.unrealengine.com/u/Kochab)\
**Post date:** [November 3, 2017, 11:48am UTC](https://forums.unrealengine.com/t/how-do-i-reference-variables-in-different-plugin-files/408580/2 "2017-11-03T11:48:08Z")

</div>

Figured it out! First, you need to make a way for `PluginComponent.cpp` to get the plugin (or module).

Add this to your `Plugin.h`:

```
static inline FPluginModule& Get()
{
	return FModuleManager::LoadModuleChecked< FPluginModule >( "PluginName" );
}

```

`PluginName` should be the same name you chose for your plugin. This is found in your `Plugin.uplugin` file under `Modules` \> `Name`.

Then in `PluginComponent.cpp` you can access your `Plugin.cpp` variables via:

```
FPluginModule::Get().yourPublicVariable;
```

---

<div class="post-metadata">

**Author:** ![Joao\_Socas](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Joao\_Socas](https://forums.unrealengine.com/u/Joao_Socas)\
**Post date:** [August 6, 2021, 6:43pm UTC](https://forums.unrealengine.com/t/how-do-i-reference-variables-in-different-plugin-files/408580/3 "2021-08-06T18:43:52Z")

</div>

Thank you very much for sharing your answer! Helped me a lot!
