x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Plugin: keeping an object alive for the whole game

Hello,

I am developing a Plugin that exposes a network API.

The main entry point of this API is a plain C++ object named Client that represents a connection to a server.

Once the API user has created the Client (there usually is only one), I want this Client to persist across levels (the goal is to keep the connection open). Destruction of the Client should only occur if the user explicitly asks for it.

So far, I have found two ways to achieve this:

  1. Store the Client directly in the plugin's module object (the one that inherits from IModuleInterface).

  2. Store the Client in a custom UObject, which is added to the root set when created.

Both these options have worked fine so far, but they share a common problem: when using Play in Editor, the Client is kept alive after the Play session ends, which I do not want.

I am looking for a non-intrusive way to prevent the Client object from outliving a Play in Editor session. By non-intrusive, I mean that I want it to be transparent to the user of my plugin (i.e. they should not have to create a custom GameInstance to hold a reference to the Client, etc.).

Is this at all possible? Thanks in advance.

Product Version: UE 4.15
Tags:
more ▼

asked Mar 15 '17 at 02:46 PM in C++ Programming

avatar image

hector-storm
15 1 3 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

There variues PIE events in FEditorDelegates which you can bind to, they are static, look up in constants:

https://docs.unrealengine.com/latest/INT/API/Editor/UnrealEd/FEditorDelegates/index.html

remember to use #if WITH_EDITOR and make diffrent initiation code for editor and game builds

more ▼

answered Mar 15 '17 at 07:55 PM

avatar image

Shadowriver
37.3k 936 172 1116

avatar image hector-storm Mar 16 '17 at 11:02 AM

FEditorDelegates::EndPIE is just what I was looking for :) Thanks a lot! It's strange I didn't hear about it until now despite all the research I've done.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

If you have someplace that runs any Tick/PerFrame logic, you could probably try something like this:

 // Some Tick method either in the Module or custom UObject (make sure you set bCanEverTick to true...)
 
 void CustomUObject::Tick(float DeltaTime)
 {
 #if WITH_EDITOR
   if (GEngine->GetWorld() == nullptr)
   {
      // We were running in-editor, manually clean up the client connection.
      // ...
   }
 #endif
 }
more ▼

answered Mar 15 '17 at 06:16 PM

avatar image

ExtraLifeMatt
1.6k 34 14 48

avatar image hector-storm Mar 16 '17 at 11:08 AM

Indeed I have someplace in my code where I could do that. I'll use Shadowriver's solution as it looks cleaner, but thanks for giving me the idea anyway, this could prove useful.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question