# How to create a global actor for simulation management

**URL:** <https://forums.unrealengine.com/t/how-to-create-a-global-actor-for-simulation-management/474537>\
**Category:** Character & Animation\
**Tags:** playercontroller, controller, actor-blueprint, unreal-engine, simulation, question\
**Created:** [November 16, 2020, 5:35am UTC](https://forums.unrealengine.com/t/how-to-create-a-global-actor-for-simulation-management/474537 "2020-11-16T05:35:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![OzMomotaro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OzMomotaro](https://forums.unrealengine.com/u/OzMomotaro)\
**Post date:** [November 16, 2020, 5:35am UTC](https://forums.unrealengine.com/t/how-to-create-a-global-actor-for-simulation-management/474537/1 "2020-11-16T05:35:08Z")

</div>

**Background**  
I have been developing a test simulation that has an arbitrary number of autonomous vehicles moving around an automatically generated environment - with a number of autonomous turrets that fire projectiles. There are NO player controllable entities in the level - but I was hoping to have a Master Controller actor to manage a sequence of simulation runs, and also handle data I/O operations (such as data saving), and possibly world re-building. The simulation works well apart from this Master Controller. For info - the sim\_controller just calls a C++ function to save the output\_data to a CSV file.

**Problem**  
When I create a sim\_controller actor (which stores Output\_Data - see below) with a test custom test event (Test\_Event), I cannot seem to call/trigger these events from any of the other actors (in the second image this was from a separate actor BP). I have created a local variable (Master is of type sim\_controller) have tried triggering the Test\_Event both directly and through cast\_to\_class approach. Neither approach however seems to trigger the sim\_controller event. I also have an instance of the sim\_controller actor dropped into the level for good measure.  
I assume the issue is that creating a variable within another actor BP is at best creating a separate instance, and not a truly global.

EDIT - the examples below are highly simplified to highlight what I tried to implement more broadly.

 ![322171-sim-controller-bp.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/5/2/c52d4515fe277d5b917621c7f911bcce9b1c68dd.jpeg)

 ![322172-turret-bp.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/4/c/04c8785f4c942dbb6a8d5615b4eb8320e4146e62.jpeg)

**Question**  
If I want to communicate with the sim\_controller actor (instantiated in the level) - do I need to spawn all the vehicles/turrets from that sim\_controller, and pass through reference to the global sim\_controller? I don’t want to really try and create a local instance of the sim\_controller with in the vehicle/turret BP, because I want to be able to destroy these between runs.

Once again sorry for the noob question - but I can’t find tutorials on developing global controllers that weren’t part of the player controllable actor (which I don’t have). Or do I need to make the sim\_controller actor player controllable?

---

<div class="post-metadata">

**Author:** ![OzMomotaro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OzMomotaro](https://forums.unrealengine.com/u/OzMomotaro)\
**Post date:** [November 18, 2020, 6:38am UTC](https://forums.unrealengine.com/t/how-to-create-a-global-actor-for-simulation-management/474537/2 "2020-11-18T06:38:05Z")

</div>

Answered my own question - and for anyone with a similar question I would recommend the following UE4 [UE4 BP Communications Tutorial][1]. I should have watched this a long time ago, as it simplified things enormously (as I had erroneously believed that you could access global class functions without having a specific instance - and had assumed that you could transmit signals to all (both wrong).

**One Solution:** Create a BP Interface for the different types of comms data… for example when you want to transfer data between actors (in this case one actor is a simulation controller). I will caveat this with the fact that I’m a noob - so my solution may not be the best/neatest/good-practice. There are other ways, but I like this one - you use the interface to effectively create a 1-1 communications channel between objects/actors etc… the trick is that you need to have a unique instantiated object reference (not just a class reference). In this case the Sim\_Controller is just a stock standard actor, but you will want to have a reference to it in each actor/element that needs to communicate/transfer to it (in this case autonomous vehicles and turrets).

Step 1: Create Interface BP with functions that relate to event-triggers - the interface should contain ‘functions’ that relate to the unique types of command/data-transfer that you want to undertake (each one will generate an event that can be listened to by the Sim Controller (in this case). The “function” is also defined by the data structures that are being transferred.

 ![322389-controller-interface.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/8/d/e8d3f7c12f40444625bdf9e110a56b1ca4a41b45.jpeg)

Step 2: Create a Send Signal/Event from the object/actor that is transmitting information/data (in this case to a global controller). This is done by calling the function, and attaching both the appropriate data structure from your send object/actor.

 ![322390-send-transfer-event.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/3/a/b3ac7b899b586f329b9365ac53c69da915b7a763.jpeg)

Step 3: Obtain a unique/specific reference to the Sim Controller… I know this is NOT the most elegant solution, but as I only have a single Sim Controller actor in the game, I can do a simple get all actors of class call. This reference is used for the actual comms transfer, as you need to know the specific instance (not class) of the object/actor/etc.

 ![322401-find-receiver-reference.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/d/7/4d761fb2583a4b159d55d147cf979300663fc7b3.jpeg)

Step 4: Create an event listener in the receiving actors (Sim Controller) that reacts to the signal/event that is transmitted to it. As you need to include a specific object reference in the call (in step 2/3) only this actor will need to react to it.

![322402-receive-transfer-event.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/9/2/392c55e5048dd7c240699cbf9a120044af2bfc66.jpeg)

As I said - this is pretty basic stuff, and I’m sure there are other ways of doing this (like casting directly to the actor - if you are able to extract the reference from a collision for example). Let me know if there are better ways of doing this.

---

<div class="post-metadata">

**Author:** ![Alekann01](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Alekann01](https://forums.unrealengine.com/u/Alekann01)\
**Post date:** [November 19, 2020, 5:45am UTC](https://forums.unrealengine.com/t/how-to-create-a-global-actor-for-simulation-management/474537/3 "2020-11-19T05:45:45Z")

</div>

Hi OzMomotaro

There are different ways you could approach this. The easiest way would be to store a reference in the Game Mode class as the game mode should be accessible by all objects (unless this is a networked application).

1. Create a custom Game Mode class
2. Go to project settings → Maps and Modes → Assign the custom game mode (Or assign it in the world outliner as an override if you prefer).
3. Add a variable to store the reference to the sim controller
4. Inside your sim controller class, on BeginPlay call GetGameMode → Cast to custom Game Mode → Set the sim controller reference to self.
5. Now all other objects can access the sim controller through the Game Mode providing at least one instance of the sim controller exists.

Unless you are using the sim controller to set or manage the positions of the objects in design time, it might be better to use classes designed to handle the rules of the game / level and users such as Game Instance, Game Mode and Player Controller instead of just using a standard actor.

Good luck

Alex

---

<div class="post-metadata">

**Author:** ![OzMomotaro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OzMomotaro](https://forums.unrealengine.com/u/OzMomotaro)\
**Post date:** [November 19, 2020, 5:59am UTC](https://forums.unrealengine.com/t/how-to-create-a-global-actor-for-simulation-management/474537/4 "2020-11-19T05:59:07Z")

</div>

Thanks for that Alex - as I said, I’m sure my answer was likely not the best (or most elegant). The challenge with jumping into something like UE4 is that your solutions tend to reflect more your experience (“everything looks like a nail…”). So thanks for the different option. I also felt that game mode should enable a sim-variant, so your approach looks neater (though I don’t have any experience with game modes). Much appreciated… but I wanted to put down my own (simple) approach just in case anyone like me had no idea - and also as a way of giving a nudge to all the better ideas out there.

Edit - I was going to actually try and use Python to do most design-time control functions through the scripting (though it would be better if there were more in-built methods to also use python at run-time).

Edit-edit 🙂 so from what I can interpret from your answer, the advantage is that this pre-configures all objects (etc) to have a link to the game-mode derived sim\_controller? So this removes the need to have dedicated calls/assignments to local sim\_controller classes (ie my get\_all\_actors\_of\_class approach to create local references on all actors that need to communicate with the controller?). Sorry if that’s a nonsense question.

---

<div class="post-metadata">

**Author:** ![OzMomotaro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OzMomotaro](https://forums.unrealengine.com/u/OzMomotaro)\
**Post date:** [November 20, 2020, 12:37am UTC](https://forums.unrealengine.com/t/how-to-create-a-global-actor-for-simulation-management/474537/5 "2020-11-20T00:37:50Z")

</div>

Alex - tried that and it makes sense. This is going to sound very noob, however does this mean that every time you want to access the Sim\_Controller (from custom Game Mode) you need to cast (Get Game Mode \> Cast to Sim\_Mode \> pull off Sim\_Controller \> access any functions/variables (see below).

 ![322538-question1a.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/f/4/9f434ddd884b04a467424050ae29caac4e0c6558.jpeg)

Would it not be better to still have a local reference to this Controller in the actor BP, to simplify this? For example you create a reference at Begin\_Play? If so, then the only advantage of putting it in the custom Game Mode (Sim\_Mode) is that you guarantee initialization before any other BP?

![322539-question1b.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/6/4/a640a79a4fd0e1af293a9e5ac5d963ccd423e9df.jpeg)

Am I missing something obvious? Thanks in advance

---

<div class="post-metadata">

**Author:** ![HappyHappyPlay](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HappyHappyPlay](https://forums.unrealengine.com/u/HappyHappyPlay)\
**Post date:** [February 9, 2022, 8:26pm UTC](https://forums.unrealengine.com/t/how-to-create-a-global-actor-for-simulation-management/474537/6 "2022-02-09T20:26:33Z")

</div>

I know this is old but in case anyone’s runs into this:

To answer your latest question, you could create a helper function to wrap "Get Game Mode \> Cast to Sim\_Mode \> pull off Sim\_Controller ", that way it becomes “GetSimController” and you can use it immediately.

That function could potentially be a member or even a global function as described here:

> [@Possible to make "global" functions?](https://forums.unrealengine.com/t/possible-to-make-global-functions/82165/2):
>
> The function library is what you are looking for. Right click - blueprints - blueprint function library.

Of course what you mentioned about doing it in the BeginPlay could also work, but it could be nicer to avoid storing it everywhere and potentially having stale data (albeit unlikely).

---

<div class="post-metadata">

**Author:** ![Loialest](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Loialest](https://forums.unrealengine.com/u/Loialest)\
**Post date:** [September 24, 2024, 7:37pm UTC](https://forums.unrealengine.com/t/how-to-create-a-global-actor-for-simulation-management/474537/7 "2024-09-24T19:37:40Z")

</div>

I also know this is old but another approach could be to create a subsystem ( [Programming Subsystems in Unreal Engine | Unreal Engine 5.4 Documentation | Epic Developer Community (epicgames.com)](https://dev.epicgames.com/documentation/en-us/unreal-engine/programming-subsystems-in-unreal-engine).

GameInstance Subsystems can be accessed pretty easily from blueprint. You could then have both your sim\_controller and other actors register themselves to the subsystem and handle whatever kind of functionality and communication you want through it.
