Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gt callback with python variables #564

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

getnamo
Copy link

@getnamo getnamo commented Oct 22, 2018

Took longer than expected to get the time to make the pull request, but as per request #181 (comment)

This variant will allow you to pass in a variable such as a python object in the callback. Example use case here

def train_blocking(self):
	...
	#python object
	summary = {}
	summary['elapsed'] = stop-start

	#call back with results on game thread
	ue.run_on_gt(self.training_complete, summary)

...
#actual function getting called on game thread with data
def training_complete(self, summary):
	#not related, but forward summary python object to blueprint layer as json string
	self.uobject.OnTrainingCompleteFunction(json.dumps(summary))

https://github.com/getnamo/tensorflow-ue4/blob/master/Content/Scripts/TensorFlowComponent.py#L164

Note that this particular call uses an alias defined here: https://github.com/getnamo/UnrealEnginePython/blob/b652cbfd759da6045a2f89c4d4080526b33d3c47/Source/UnrealEnginePython/Private/UEPyModule.cpp#L501, alias not required for functionality and it's not included in the pull request. Instead you would write:

ue.create_and_dispatch_when_ready(self.training_complete, summary)

For the other route (game thread->run something on background thread) it's probably better to use python's Thread model (see: https://github.com/getnamo/UnrealEnginePython/blob/master/Content/Scripts/upythread.py for an example)

@getnamo getnamo mentioned this pull request Oct 22, 2018
@rdeioris
Copy link
Contributor

Hi, thanks for the patch, can you extend it to allow customizing the thread to use ? (currently it only use the GameThread). Note that the last Py_INCREF(Py_None) is not required, as it is implicit in Py_RETURN_NONE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants