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

How to run a simple python function, with inputs & outputs, from blueprints? #889

Open
TylerDuncan opened this issue Mar 19, 2023 · 5 comments

Comments

@TylerDuncan
Copy link

I searched the forum for this issue specifically but didn't see any answers that seemed to fit.

If I wanted to write a python function that took an integer as input, squared it, then spit out the new integer as an output, how do I call this from a blueprint node? The current execute python method is just a string input for path with no other inputs or outputs.

Cheers,
Tyler

@TylerDuncan
Copy link
Author

Ah! So you’re passing in the arguments by calling the method with the arguments in the same string? That makes sense now that I think about it.

I did think about using text files or CSV for the output data, but it feels like there has to be a better way to pass data back.

I suppose I could place the code on an actor, and run the execute python string for the input. Then create a blueprint function that takes inputs, and call that function from the python script to pass the data back? I may be creating issues with this process but it’s worth a shot.

@TylerDuncan
Copy link
Author

I took another stab at it tonight and got farther! I've successfully been able to call a function in the python script, pass an argument to the function (number as a string), run the function that multiplies the number by itself, then print to console, and print screen, the output of multiplication.

My next tests will be:

  • See if I can import a python library and then print to string some output from using the library.
  • See if I can create a custom blueprint node that lets me pass back more than just a string or bool. These "execute actor method" functions are written in the plugin so maybe I can replicate them and add more output types.
  • If I can't pass back anything but a string, then I'll test passing back multiple arguments as a combined string and separating them in blueprint code, then try using them.

To answer your question: I believe I have seen a way to set the value of a variable from blueprint code. It's either in the examples or the docs on github. Depending on if you're creating the actor from code then referencing it, or getting the actor in python via some find by class method. I haven't successfully done this yet, because I'm still not able to get a reference to the actor properly in python. I just tried for half an hour but didn't get anywhere. I see there are "set python attr int" and other nodes for python character or component. I'm trying from a PyActor but those nodes don't exist there.

@TylerDuncan
Copy link
Author

@tempaccountforissue Agreed. If I can figure out how to pass a proper reference, I think that would solve a lot of overall issues.

I believe this is the document I'm referring to. It requires you to use it as a uobject which I'm hoping isn't editor only. Do you have any idea?

https://github.com/20tab/UnrealEnginePython/blob/master/docs/uobject_API.md

@TylerDuncan
Copy link
Author

@tempaccountforissue I think you can break the struct up and pass it back and forth as a string if absolutely necessary, it would just be more tedious to have to convert it back and forth. I also don't know if that doc is old and maybe they are supported now?

@TylerDuncan
Copy link
Author

@tempaccountforissue Unfortunately, I never figured out how to get this to properly work. I think I lack the understanding of c++ to do so. Instead I’m attempting to pay someone on fiverr to just create me a c++ library that will hopefully do what I wanted to do in Python, natively in c++. If you ever figure it out, let me know!

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

No branches or pull requests

1 participant