Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
FuzzySlippers
Feb 6, 2009

I found Ink a bit too cumbersome for my non-story focused rpg and I'd think trying to integrate Python would be even worse. If you have to go that route it seems like lua is far more common and there's a bunch of ways to get it into Unity. I don't recall which one I used but when I did it for a prototype it was pretty simple.

I used this plain text parsing dialogue engine as the basis for something I customized to my needs and it is working fine. Your example of needing to bounce back and forth between conversation and other UI windows I found pretty easy to implement like this. I changed Rumor so the plain text files are processed ahead of time in a ScriptableObject where it collects those variables so they can be drag dropped in the inspector without any Resources loading remember the filename nonsense. So I get inspectors when it helps but otherwise can write dialogue in plain text.

I think the hell with RPGs is all the drat content you have to make. Good tools are great and all but don't let it derail you into endless tool revision and overspecing. I spent a good while making a clean modular ability system so that arbitrary combinations of effects could be combined in any way without special coding. Of course almost all of the abilities use only the simplest aspects and I would've saved a lot of time to just custom code the handful of complicated spells. Not like I have to worry about some designer poking around in my code.

Adbot
ADBOT LOVES YOU

Veni Vidi Ameche!
Nov 2, 2017

by Fluffdaddy
I have problems with Unity. Not functionally, but conceptually.

Despite having worked with Unity off and on for many years, and on many projects, I've never really been comfortable with it. Sometimes I muddle through, and other times I get frustrated and taper off a project, or just plain give up on it. I go through long stretches without touching Unity, which doesn't help.

I feel like this is probably a me problem, and not a Unity problem.

One recurring problem I have is not being able to find a satisfactory way to organize my scenes, and objects within them. For instance, in one of my current projects, I have managed to wind up with a hierarchy that looks something like this:
code:
Monolith
  -> LevelManager
    -> GameBoardManager
      -> [Array of entities managed by the board manager]
  -> InputManager
I find that working with this becomes burdensome, and I'm never happy with any solution I come up with. I waste time trying to decide whether some particular responsibility falls on the LevelManager, or the GameBoardManager. Once I make a decision, I will eventually find an edge case (and sometimes a central case) which makes my choice impractical. I've tried massive, monolithic entities that control everything. I've tried passing billions of messages around. I've tried hybrid approaches. I'm not happy with anything I've come up with.

This doesn't happen to me in projects where I just pick a language, and write all the code from scratch. For some reason, I can't seem to project my way of thinking onto my Unity projects, or adjust my organizational tendencies to work with Unity. I occasionally have similar problems with pure code frameworks.

I am looking for papers, or videos, or tutorials of any type that can help me get my head straight on this stuff. I want Unity tutorials, and not programming tutorials. Think, "Babby's first Unity scene." I don't mind paying for training materials, if they are worthwhile. I don't mind paying for Assets that will help me solve my problems. I just want to be able to site down and write a game, from start to finish, without feeling like I am constantly battling with the tools I've chosen. I can, of course, choose to never use Unity, again, but that's not what I want.

The tl;dr is that I want Unity training materials that focus on Unity concepts, and not on programming.

Doc Block
Apr 15, 2003
Fun Shoe
Have you watched any of the videos that Unity themselves have put up?

Veni Vidi Ameche!
Nov 2, 2017

by Fluffdaddy

Doc Block posted:

Have you watched any of the videos that Unity themselves have put up?

I have, but it's been a while. I remember being really unimpressed with it in the past. I'm looking, now, and it actually looks pretty good. I'd still like suggestions about any specific video authors, or video series, that deal with this. I'm especially interested in things that deal with the theory of how and why to organize things in a given way.

Nude
Nov 16, 2014

I have no idea what I'm doing.

Veni Vidi Ameche! posted:

I have problems with Unity. Not functionally, but conceptually.

Despite having worked with Unity off and on for many years, and on many projects, I've never really been comfortable with it. Sometimes I muddle through, and other times I get frustrated and taper off a project, or just plain give up on it. I go through long stretches without touching Unity, which doesn't help.

I feel like this is probably a me problem, and not a Unity problem.

One recurring problem I have is not being able to find a satisfactory way to organize my scenes, and objects within them. For instance, in one of my current projects, I have managed to wind up with a hierarchy that looks something like this:
code:
Monolith
  -> LevelManager
    -> GameBoardManager
      -> [Array of entities managed by the board manager]
  -> InputManager
I find that working with this becomes burdensome, and I'm never happy with any solution I come up with. I waste time trying to decide whether some particular responsibility falls on the LevelManager, or the GameBoardManager. Once I make a decision, I will eventually find an edge case (and sometimes a central case) which makes my choice impractical. I've tried massive, monolithic entities that control everything. I've tried passing billions of messages around. I've tried hybrid approaches. I'm not happy with anything I've come up with.

This doesn't happen to me in projects where I just pick a language, and write all the code from scratch. For some reason, I can't seem to project my way of thinking onto my Unity projects, or adjust my organizational tendencies to work with Unity. I occasionally have similar problems with pure code frameworks.

I am looking for papers, or videos, or tutorials of any type that can help me get my head straight on this stuff. I want Unity tutorials, and not programming tutorials. Think, "Babby's first Unity scene." I don't mind paying for training materials, if they are worthwhile. I don't mind paying for Assets that will help me solve my problems. I just want to be able to site down and write a game, from start to finish, without feeling like I am constantly battling with the tools I've chosen. I can, of course, choose to never use Unity, again, but that's not what I want.

The tl;dr is that I want Unity training materials that focus on Unity concepts, and not on programming.

You and I have overlapping frustration, and I too have been trying to figure out the Unity way and each time I've been unsatisfied. The one thing I've avoided, and perhaps I shouldn't, is the asset store. I wonder what genre of games have you been making? I've personally noticed the monobehaviour style clicked more when I was prototyping a first person game. But I felt like I was going against the grain when making a turn based tactics game. I listened to a podcast with a Unity dev and he mentioned some interesting notes such as to treat scenes as you would treat layers in photoshop. I would love to see how this is done in practice.

FuzzySlippers
Feb 6, 2009

Nude posted:

But I felt like I was going against the grain when making a turn based tactics game. I listened to a podcast with a Unity dev and he mentioned some interesting notes such as to treat scenes as you would treat layers in photoshop. I would love to see how this is done in practice.

There is a lot of RPG-ish stuff that feels dumb to have as monobehaviours. Like having mono/gameobjects for command pattern was clutter. This isn't helped by awkward Unity tutorials that shove everything in mono files even if it doesn't make sense. Scriptableobjects work a lot better for a place to put easy visual debug info without a lot of mono clutter.

I definitely do a lot of additive scene loading like that. Like my UI is in its own scene so it can be essentially a nested prefab and I can load it into any scene. Similarly my main camera / player object and world map have their own scenes. The one problem is that some Unity tools like baked culling get completely broken with additive loading so those have to be loaded normally but you can add load in everything else around it.

Mooey Cow
Jan 27, 2018

by Jeffrey of YOSPOS
Pillbug

Rocko Bonaparte posted:

I don't understand the problem here. Do you mean using Unity's own JavaScript stuff? I never even touched it so I don't know how it works. Do you mean they're compiling that beforehand and then locking it down?

I just looked at DLR JavaScript implementations and... yeap that sucks.
No, not Unity's "Javascript" (which should have never been called that because it's not). I looked for fully managed Javascript engines, but instead of being interpreted and "slow" and "working", they prided themselves with using C#'s reflection utilities to emit new IL bytecode which could be JIT compiled, and be "fast". Unfortunately, on iOS and several other platforms, all code is "Ahead-of-time" compiled, and the code emission facilities don't work. Things like using Enum keys in generic Dictionaries don't work out-of-the-box for the same reason. Instead you'll get a nice runtime exception on first usage. (Frankly I think they ought to be able to catch the use of Reflection.Emit at build time and at least give a warning...)

So if IronPython is also like that, be aware that you may run into problems when porting to other platforms.

quote:

Edit: A big thing I think I need is to be re-entrant. That's a tricky one with embedding Python here. Ink was nice to be able to pick up the conversation where I left off, and I could shoehorn some logic to reset if that's what I actually wanted.
You could maybe abuse Python's generators in the same way that Unity abuses them in C# for their coroutines.
code:
yield playDialog("whatever")
do the things
results = BuyResults()
yield showBuyMenu("what up", results)
or something like that maybe. You'd have to have something that keeps track of your yielded generators and increment them when the thing they yield is done, e.g. when the dialog has finished playing.

limaCAT
Dec 22, 2007

il pistone e male
Slippery Tilde

Veni Vidi Ameche! posted:

I have problems with Unity. Not functionally, but conceptually.

Despite having worked with Unity off and on for many years, and on many projects, I've never really been comfortable with it. Sometimes I muddle through, and other times I get frustrated and taper off a project, or just plain give up on it. I go through long stretches without touching Unity, which doesn't help.

I feel like this is probably a me problem, and not a Unity problem.

One recurring problem I have is not being able to find a satisfactory way to organize my scenes, and objects within them. For instance, in one of my current projects, I have managed to wind up with a hierarchy that looks something like this:
code:
Monolith
  -> LevelManager
    -> GameBoardManager
      -> [Array of entities managed by the board manager]
  -> InputManager
I find that working with this becomes burdensome, and I'm never happy with any solution I come up with. I waste time trying to decide whether some particular responsibility falls on the LevelManager, or the GameBoardManager. Once I make a decision, I will eventually find an edge case (and sometimes a central case) which makes my choice impractical. I've tried massive, monolithic entities that control everything. I've tried passing billions of messages around. I've tried hybrid approaches. I'm not happy with anything I've come up with.


Unity noob here and hoping for an answer... but I wonder if you can just define different scripts as different components (like the builtin ones, rotation, material...) and compose your project like that.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Mooey Cow posted:

No, not Unity's "Javascript" (which should have never been called that because it's not). I looked for fully managed Javascript engines, but instead of being interpreted and "slow" and "working", they prided themselves with using C#'s reflection utilities to emit new IL bytecode which could be JIT compiled, and be "fast". Unfortunately, on iOS and several other platforms, all code is "Ahead-of-time" compiled, and the code emission facilities don't work. Things like using Enum keys in generic Dictionaries don't work out-of-the-box for the same reason. Instead you'll get a nice runtime exception on first usage. (Frankly I think they ought to be able to catch the use of Reflection.Emit at build time and at least give a warning...)

So if IronPython is also like that, be aware that you may run into problems when porting to other platforms.

I have to figure this out. Classic CPython does compile before running .py files into .pyc files. I see a Compile() function in the IronPython ScriptEngine. I don't need to use it. I was able to ram a string right into it. However, I pondered that and wondered if I'd want to try running that function on all .py files in my resources when building. Can you do something similar?

quote:

You could maybe abuse Python's generators in the same way that Unity abuses them in C# for their coroutines.
Python does have a yield statement and I was doing something with it. I couldn't figure out how to make it work in the main script's scope, but if I have a standard class name in my script and standard function, then I can invoke that. The yield returns a generator; Python's semantics for a re-entrant function and its context. I just bang on that thing until I get a particular kind of exception back. I believe that exception is lightweight...

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Unrelated Unity question: Can somebody explain how to use something like a rectangle mask with a text box (TextMeshPro?) to do something like a scrolling NPC text? I'm trying to do something where it shows a subsection of a string, then shows the next section when the magic use button is pressed.

I have an implementation of this that uses, like, four labels and automatically wraps text based on the amount of pixels the amount of string it has drawn has consumed. That code is completely disgusting and really finicky so I'd rather just defer to new Unity UI constructs. I heard the 2d rectangle mask could do something for me here but I have no idea. The Unity API page for it just acknowledges the thing exists.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Rocko Bonaparte posted:

Unrelated Unity question: Can somebody explain how to use something like a rectangle mask with a text box (TextMeshPro?) to do something like a scrolling NPC text? I'm trying to do something where it shows a subsection of a string, then shows the next section when the magic use button is pressed.

I have an implementation of this that uses, like, four labels and automatically wraps text based on the amount of pixels the amount of string it has drawn has consumed. That code is completely disgusting and really finicky so I'd rather just defer to new Unity UI constructs. I heard the 2d rectangle mask could do something for me here but I have no idea. The Unity API page for it just acknowledges the thing exists.

Throw a RectMask2D component on a parent of your text. Size it to what you want.. it just works? :shrug:

KoRMaK
Jul 31, 2012



I use an MVC architecture for my Unity stuff as best I can.

Code and stuff goes under the src directory that I created, and in there is Models/ Views/ Controllers/ (so far unity only really uses models and controllers. I don't have too much view specific code going on)

Then, I create a scenes folder in the root folder and stash my scenes there. Everything in the Src folder should be agnostic of scene stuff - any scene could use the code if it wanted.

As for prefabs, they go in the prefab directory and I either have them prefixed with their scene if they are scene specific, or nothing if they are agnostic.

KoRMaK
Jul 31, 2012



KoRMaK posted:

I have what seems to be a terribly optimized method, in Unity, that is drawing to the screen every frame.

I'm using physics objects to get some raw data, projecting their position to the screen, and using that to populate voxel data that I then run marching squares on and draw the marched data to the screen. It's running badly, I drop from like 250fps or 120fps to 30 when I turn the marching cubes rendering on.

I feel like I should do this drawing as a shader but I'm not really sure, I've also never written a shader before as much as I want to/need to.

Here's my code, there's 3 nested for loops that I'm pretty sure aren't helping, but I'm not sure how to optimize it. I'd like to hear what suggestions for optimizations you here could offer. Any would be appreciated! I implemented a quad tree to help cut down on areas that I don't have to render, and that helped a bunch but not enough. I ideally want to have like 50 physics objects on screen at once and keep my fps above 60, or at least 30.

https://github.com/KoRMaK/IsometricLiquid/blob/c75a4a95b8e5b758772763857e9b4fc530ea9c41/Assets/src/ScreenDrawer.cs#L82 Comment out lines 81-85 and you get a huge fps jump. Comment out line 81 and 82 or 83 separately and you get a big fps jump.


If you clone this repo, you should be able to open it in Unity and start running it, so feel free to play around in it if you want to see the heck I've created for myself.

Update on this! things are better, my fps is up way high, which means I can add more physics objects. Where I was at 5 objects and like 1.5fps, I am now up to 25 objects and 30fps. Very good! I basically removed a bunch of division math from the decleration of for loops and moved them around to be in places where they wouldn't be calculated more than they needed to be.

Then I plugged in the kinect and it too is working!

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

leper khan posted:

Throw a RectMask2D component on a parent of your text. Size it to what you want.. it just works? :shrug:

I'm having some strange thing happen when I set parents in code. I end up doing this because I have a general overlay canvas that isn't available until runtime. Whenever this happens, it seems to do something strange with the anchor settings and ends up flinging the UI element God-knows-where. The solution generally is to set the anchored position, min offset, and max offset to all zeroes. I don't know why. I'm bringing up this nonsense because nothing ever just seems to work. Also, I still don't know what I'm supposed to be moving in that case when I scroll. Am I moving the mask or the text? I'm assuming the text.

I just want some sane confirmation of what it should be like so I know to keep soldiering through the way I'm doing it.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Rocko Bonaparte posted:

I'm having some strange thing happen when I set parents in code. I end up doing this because I have a general overlay canvas that isn't available until runtime. Whenever this happens, it seems to do something strange with the anchor settings and ends up flinging the UI element God-knows-where. The solution generally is to set the anchored position, min offset, and max offset to all zeroes. I don't know why. I'm bringing up this nonsense because nothing ever just seems to work. Also, I still don't know what I'm supposed to be moving in that case when I scroll. Am I moving the mask or the text? I'm assuming the text.

I just want some sane confirmation of what it should be like so I know to keep soldiering through the way I'm doing it.

The default for the second parameter in SetParent is true. You probably don’t want to keep world position, so try setting that to false.

https://docs.unity3d.com/ScriptReference/Transform.SetParent.html

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

leper khan posted:

The default for the second parameter in SetParent is true. You probably don’t want to keep world position, so try setting that to false.

https://docs.unity3d.com/ScriptReference/Transform.SetParent.html

Thank you! That seems to be the missing magic. It worked at least twice.

Veni Vidi Ameche!
Nov 2, 2017

by Fluffdaddy

Nude posted:

You and I have overlapping frustration, and I too have been trying to figure out the Unity way and each time I've been unsatisfied. The one thing I've avoided, and perhaps I shouldn't, is the asset store. I wonder what genre of games have you been making? I've personally noticed the monobehaviour style clicked more when I was prototyping a first person game. But I felt like I was going against the grain when making a turn based tactics game. I listened to a podcast with a Unity dev and he mentioned some interesting notes such as to treat scenes as you would treat layers in photoshop. I would love to see how this is done in practice.

The Asset Store is actually pretty great. The problem is finding an asset that solves your specific problem. For instance, there are a thousand character controllers, but there might only be one, or none, that really fit your particular needs, and it's very hard to determine which is which before you buy it.

I mostly make 2D platformers, puzzle games, and one-button casual games. That made Unity an even less appropriate choice in the past, and I bought all of the 2d helper assets. Some of them were pretty great, but, again, it was the same problem I mentioned in the previous paragraph: many of them did part of what I wanted, but none of them did it all. I ended up using one asset just to generate collision data, because it was the only one with a really complete system for generating complex collision masks, another asset for 2D animation, and another for its character controllers, and so on. This is less of a problem with Unity having official 2D support, now.

Genre is likely part of the problem, but I feel like Unity should be pretty flexible, by now.

chin up everything sucks
Jan 29, 2012

Hey, I just started following this thread, and I wondered if there was an IRC channel or Discord that people in this thread hang out in.

I'm looking at making a crazy space-empire game where all of your information is restricted by communication-speed limitations. In-system communications are limited by speed of light, between-system is limited to ships acting as information couriers. The entire idea is that you have to set up systems for keeping everything running without you being able to rapidly micro-manage what is going on. I'm probably going to use Unity and make it 2-d, have each system store a list of what moved where at each increment of time, and each unit in the system will reference the system-log for anything that it can see or has had information passed to it about.

I think to start I just need to be able to create a circular unity map with layers that I can hide showing friendly and non-friendly movement tracks in different colors.

Stick100
Mar 18, 2003

Nude posted:

I listened to a podcast with a Unity dev and he mentioned some interesting notes such as to treat scenes as you would treat layers in photoshop. I would love to see how this is done in practice.

They recently added the ability to make scenes additive. Previously you could only open a single scene, now you can have multiple scenes open. An example would be to have a gamestart/UI scene that you opened on game start, while also opening the first level. This way you can show the game (behind the UI) and when they start the game you can just disable the start scene, and they are already in the first level without a load.

Then if you wanted you could use that same gamestart/UI scene but load up the second level if you know they are likely to start on the second level (primary save is now at the second level). When they start you could again just disable the start scene and be in the second level.

By doing this you could keep the logic seperated.

This isn't what they were suggesting instead I beleive they were suggesting something akin, to a lighting scene, a props scene, a geometry scene, a playables scene. Then if you wanted you could disable specific scenes, to let you see the game without props, or enemies.

This would also let you build the levels in teams since there isn't a good system of scene checkout / merge in Unity yet.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Stick100 posted:

They recently added the ability to make scenes additive. Previously you could only open a single scene, now you can have multiple scenes open. An example would be to have a gamestart/UI scene that you opened on game start, while also opening the first level. This way you can show the game (behind the UI) and when they start the game you can just disable the start scene, and they are already in the first level without a load.
Oh that's quite nice. I had prototyped my main menu in a separate scene, and then just dumped out the root of the UI into a prefab to poo poo out in the regular game. It would be nicer if I could just play with the scenes separately like that. Can the scenes interact?

Linear Zoetrope
Nov 28, 2011

A hero must cook
Is there still an industry/job tips thread for the game industry? I swear there used to be but I can't find it. The closest I see is the "ask a game designer" thread in Games.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Linear Zoetrope posted:

Is there still an industry/job tips thread for the game industry? I swear there used to be but I can't find it. The closest I see is the "ask a game designer" thread in Games.

https://forums.somethingawful.com/showthread.php?threadid=3415662 ?

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Last night I sat down to start the groundwork on a new character/NPC dialog box using TextMeshPro. I had previously set up a rectangular mask to show a fraction of the text at the bottom of the screen, and set up a means to scroll that. I wanted to basically implement page down. So I started doing calculations based on text size and blablabla faaaaart TextMeshPro has a page feature you can just turn on and cycle through. I didn't even need the rectangular mask!

Linear Zoetrope
Nov 28, 2011

A hero must cook

Thanks

Nude
Nov 16, 2014

I have no idea what I'm doing.

Stick100 posted:

They recently added the ability to make scenes additive. Previously you could only open a single scene, now you can have multiple scenes open. An example would be to have a gamestart/UI scene that you opened on game start, while also opening the first level. This way you can show the game (behind the UI) and when they start the game you can just disable the start scene, and they are already in the first level without a load.

Then if you wanted you could use that same gamestart/UI scene but load up the second level if you know they are likely to start on the second level (primary save is now at the second level). When they start you could again just disable the start scene and be in the second level.

By doing this you could keep the logic seperated.

This isn't what they were suggesting instead I beleive they were suggesting something akin, to a lighting scene, a props scene, a geometry scene, a playables scene. Then if you wanted you could disable specific scenes, to let you see the game without props, or enemies.

This would also let you build the levels in teams since there isn't a good system of scene checkout / merge in Unity yet.

Thanks for the insight. Is the only way to apply that style is to explicitly code it? Not that I mind, but it seems odd to me that they have support for adding multiple scenes to the hierarchy but no button or ui support for building a game based on that. Or did I miss something? I assume the workflow is something like have a main "scene" which then programmatically loads the lighting, prop, geometry scenes additively. Let me know if I'm on the right track with this.

chin up everything sucks posted:

Hey, I just started following this thread, and I wondered if there was an IRC channel or Discord that people in this thread hang out in.

I'm looking at making a crazy space-empire game where all of your information is restricted by communication-speed limitations. In-system communications are limited by speed of light, between-system is limited to ships acting as information couriers. The entire idea is that you have to set up systems for keeping everything running without you being able to rapidly micro-manage what is going on. I'm probably going to use Unity and make it 2-d, have each system store a list of what moved where at each increment of time, and each unit in the system will reference the system-log for anything that it can see or has had information passed to it about.

I think to start I just need to be able to create a circular unity map with layers that I can hide showing friendly and non-friendly movement tracks in different colors.

Sounds cool :toot:, let us know about your progress. By the way there is also another topic (making games) that offer help as well. You can post in either topic really, the unwritten rule is this is more for programming while the other is more for game design questions but you really can post any game questions in either topic. As for your last question here is the link to the discord: https://discord.gg/UwXZtgJ

Nude fucked around with this message at 05:50 on Apr 27, 2018

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Yeap I ran into a brick wall embedding IronPython. The script just smashes all the way through from top to bottom like a fridge tossed off a building. I'm having it generate text dialogs that have to be OK'd. They're just all getting queued up at once in one big burst. It's because I dispatch the dialogs to a subsystem using Coroutines, but the call that is kicking it off exits, which goes back into the Python script's scope to keep going.

Is there some coroutine tomfoolery I can try with Unity's own stuff here? I am wondering if there's a way I can have this call from Python back into my MonoBehaviour act like it's blocking from the script's point of view. I don't think IronPython itself has a good semantic for being paused, but I suspect I might be able to shove one in there somewhere. I'm not really looking forward to that notion.

limaCAT
Dec 22, 2007

il pistone e male
Slippery Tilde

Rocko Bonaparte posted:

Yeap I ran into a brick wall embedding IronPython. The script just smashes all the way through from top to bottom like a fridge tossed off a building. I'm having it generate text dialogs that have to be OK'd. They're just all getting queued up at once in one big burst. It's because I dispatch the dialogs to a subsystem using Coroutines, but the call that is kicking it off exits, which goes back into the Python script's scope to keep going.

Is there some coroutine tomfoolery I can try with Unity's own stuff here? I am wondering if there's a way I can have this call from Python back into my MonoBehaviour act like it's blocking from the script's point of view. I don't think IronPython itself has a good semantic for being paused, but I suspect I might be able to shove one in there somewhere. I'm not really looking forward to that notion.

Please post an heavily redacted example because this seems bad design but I still don't think I understood correctly what you mean.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

limaCAT posted:

Please post an heavily redacted example because this seems bad design but I still don't think I understood correctly what you mean.

Hehehe more like "no design." This is still pathfinding.

The gist is that I have a Python script like this:
code:
from UnityEngine import Debug
class ScriptMain(object):
   def run(self):
      this.Say('Hello, embedded Python non-blocking text box!')
      this.Say('This is the second statement!')
      Debug.Log('End of script')
What I want to happen is:
1. "Hello, embedded Python non-blocking text box!" shows up in my dialog subsystem.
2. The user presses the acknowledgement key.
3. "This is the second statement!" shows up in my dialog subsystem.
4. The user presses the acknowledgement key.
5. Only at this point, "End of script" appears in the log.

In reality, "End of script" appears immediately because Say() is not blocking in the script.

I wanted to minimally require a common function as an entry point so that it could use yield to suspend. At the end of the day, all my complaining may ultimately be resolved by having "this.Say" become "yield this.Say," but I am currently trying to have that function behave more intuitively. Also, having a common object gave me an easy way to embed methods while I'm screwing around with these scripts.

The Say method goes off to my dialog subsystem and displays the text on the screen. This call cannot actually block because then everything in the game would come to a screeching halt. However, I want the user to see this text and acknowledge it with a keypress. So Say() currently turns into something like this:

code:
    private IEnumerator InternalSay(string message)
    {
        var whenDone = GlobalState.Instance.DialogSubsystem.Say(message);
        yield return new WaitUntil(() => whenDone());
    }

    public void Say(string message)
    {
        StartCoroutine(InternalSay(message));
    }
(I would have just made an function-in-function but apparently that's C# 7.)

In reality--and it was obvious afterwards--what happens is the Debug.Log statement spits out its message at the end of the same frame the script was started. This is because Say() is not blocking. It spins off a coroutine and returns back to the script. So of course the script continues running. Last night, I tried to look for some means inside IronPython's internals to have it pause execution and got nowhere. It sounds like I'd have to put that in myself. My second idea is seeing if I can do something cool with await to pre-empt it. My professional work with C# stopped right when they first introduced that and I didn't have a chance until now to really use it.

Mooey Cow
Jan 27, 2018

by Jeffrey of YOSPOS
Pillbug
It seems like you actually want this.Say() to be a blocking call though. You can make it happen, if you run your python engine in a separate thread and Sleep it or whatever in your Say() function, until you get a response from the main thread. Depending on what you want to do, the required thread synchronizations may be a lot more hassle than you'd get with yield, though.

limaCAT
Dec 22, 2007

il pistone e male
Slippery Tilde

quote:

Stuff on synchronization

Yeah, it's pretty much what's happening there.

Do you need the player to actually click on the disclaimer before doing other computations?

Because at that point you have the following alternatives:

1) use a generic mailbox-style of messaging (and the second click will send an event to another component to tell it to start doing useful work)

https://unity3d.com/learn/tutorials/topics/scripting/events-creating-simple-messaging-system

Pro: one of the Unity3D endorsed systems for doing the things in the engine!
Pro: you can reuse that system for everything else.
Con: implementation may be still easy but excessive for what you are doing.

2) as above, but the second click spawns a new component with the code

Pro: you can reuse that system for everything else.
Con: implementation may be still easy, not as pont 1, but again excessive.

3) if that was a MonoBehaviour, I could also put the "send messages" in the SetUp(), and then work with a switch in the Update()

code:
switch currentstate {
  ACCEPTED: 
     // create everything else then change the state
     this.currentstate = CurrentState.FINISHED;
  FINISHED:
    // do nothing, maybe think about deactivating or destroying this gameobject here if possible...
    return;
  default:
    // do nothing, wait for the user to sell his soul
    return;
}
I am sure you can work the solution in IronPython as well

Pro: simple to use
Pro: not necessarily against the Unity Design
Con: Ugly
Con: you need to customize this behaviour for other points of your codebase

4) using futures() or promises(), and that might be a more complex solution

https://answers.unity.com/questions/725528/futures-promises-implementation-for-unity.html

Pro: So Sexy! You can resell yourself as an high-profile sex-worker business software consultant
Con: Might be too complex to set up and take too much time that could be done for something else

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I'm not sure how promises or futures could work in this situation because they'd block the main thread. I need something that is cooperative. Regarding messaging, is there some kind way to block for a message?


Mooey Cow posted:

It seems like you actually want this.Say() to be a blocking call though. You can make it happen, if you run your python engine in a separate thread and Sleep it or whatever in your Say() function, until you get a response from the main thread. Depending on what you want to do, the required thread synchronizations may be a lot more hassle than you'd get with yield, though.

Yeah I imagine I'd not only have to synchronize every single call I make into Unity libraries, but that I'd probably have to gate them to run in some global MonoBehaviour's Update loop so that they're executed at the "legal" time.

It really seems to me like I need to be able to tell the IronPython script/engine/whatever is actually running stuff to suspend itself. Then I can yield in Unity like normal.

Edit: Going waaaaay back, I remember some means of create a custom REPL which would let me thumb through the code, pass it on to be run, and otherwise decide maybe not to pass it on immediately. Performance would suck, but I am not planning to run big loops and such. So that's another avenue I might try. I had done that in another project when I wanted a script console.

Rocko Bonaparte fucked around with this message at 17:10 on Apr 30, 2018

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Rocko Bonaparte posted:

I'm not sure how promises or futures could work in this situation because they'd block the main thread. I need something that is cooperative. Regarding messaging, is there some kind way to block for a message?


Yeah I imagine I'd not only have to synchronize every single call I make into Unity libraries, but that I'd probably have to gate them to run in some global MonoBehaviour's Update loop so that they're executed at the "legal" time.

It really seems to me like I need to be able to tell the IronPython script/engine/whatever is actually running stuff to suspend itself. Then I can yield in Unity like normal.

Edit: Going waaaaay back, I remember some means of create a custom REPL which would let me thumb through the code, pass it on to be run, and otherwise decide maybe not to pass it on immediately. Performance would suck, but I am not planning to run big loops and such. So that's another avenue I might try. I had done that in another project when I wanted a script console.

You set up all the promises in a chain and push them onto whatever worker thread. Things that update the UI would of course need to get shunted back to the main thread.

The event driven solution is the simplest. I don’t understand what you’re trying to block on. The default is doing nothing until a message comes in..

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

leper khan posted:

You set up all the promises in a chain and push them onto whatever worker thread. Things that update the UI would of course need to get shunted back to the main thread.

The event driven solution is the simplest. I don’t understand what you’re trying to block on. The default is doing nothing until a message comes in..

The issue with literally blocking is that this all has been running within Unity's own thread. I can farm things off to another thread, but I'll have to synchronize calls that will reach in to any of my MonoBehaviours or the Unity library... which is just about everything.

Edit: I'm not so much concerned with the synchronization overhead so much as having to create the wrappers. What I'm looking at is what will make the script I'm trying to run look more natural without the back end being a complete abomination. I'm leaning towards having to use yields, which is a compromise on all sides. I looked online for people wanting to suspend IronPython script execution and found some old posts where people were trying to do nearly the same thing as me; they were trying to embed IronPython into a game project and wanted cooperative multithreading with the script.

Stackless Python would be perfect for this if it weren't, well, native code.

Rocko Bonaparte fucked around with this message at 06:12 on May 1, 2018

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Using threads or blocking for this kind of thing seems super weird to me. If you want to script events in sequence, you could just put the events in a queue of some sort, and consume from the queue (or advance the queue pointer) whenever the trigger happens, rather than messing with all the ugly unintuitiveness of yields or interthread communication.

I mean I guess a string of yields in a function that you only call when a trigger happens is kind of like a self-managing queue, but then it gets difficult to reset the queue or branch paths or whatever.

netcat
Apr 29, 2008

roomforthetuna posted:

Using threads or blocking for this kind of thing seems super weird to me. If you want to script events in sequence, you could just put the events in a queue of some sort, and consume from the queue (or advance the queue pointer) whenever the trigger happens, rather than messing with all the ugly unintuitiveness of yields or interthread communication.

I mean I guess a string of yields in a function that you only call when a trigger happens is kind of like a self-managing queue, but then it gets difficult to reset the queue or branch paths or whatever.

I assume the OP in the end wants to do things like
code:
doThing() // this "blocks" for a while
if (somethingIsSetByDoThing)
   doAnotherThing()
else
   doSomethingElse()
If the functions only push events to a queue that execute later, getting this kind of behaviour gets tricky and you will need to implement your own conditionals and stuff like that.

When I've been doing similar things (though in my own "engines" rather than Unity or whatever) I've either
1) implemented my own simple language that gets executed in the normal logic loop so I have complete control over the script execution
2) run the scripts in its own thread and use some kind of message passing to send events between the script thread and everything else but this gets really tedious to maintain

KillHour
Oct 28, 2007


Stick all the scripts on a stack and have the magic next button pop the stack with an event.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
The queue I'm working with is just managing the dialog window in case more than one thing is trying to slap some stuff on it. Even without that queue, the script would just flow from top to bottom without stopping to wait for the user to acknowledge any of it.

I found the main loop in IronPython and I'm giving myself another day to try to suspend it. After that I'll probably just thrown my hands down and code all these little scripts in C#.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Rocko Bonaparte posted:

The queue I'm working with is just managing the dialog window in case more than one thing is trying to slap some stuff on it. Even without that queue, the script would just flow from top to bottom without stopping to wait for the user to acknowledge any of it.

I found the main loop in IronPython and I'm giving myself another day to try to suspend it. After that I'll probably just thrown my hands down and code all these little scripts in C#.

You’re looking for threading.Event. But what everyone is saying is that this isn’t worth doing in python.

Veni Vidi Ameche!
Nov 2, 2017

by Fluffdaddy
Does anyone know where I can learn about generating crystal-like structures? I'm having a hard time finding resources. I'm looking to programmatically generate things like these:




I don't even know where to start learning the basic concepts and the math involved. I'm especially interested in doing this in 3D, but 2D is a start. I know I can brute-force it, or combine individual pre-made pieces, but I want to avoid those solutions.

Adbot
ADBOT LOVES YOU

xzzy
Mar 5, 2009

Generate a low poly cylinder, generate the end caps with a triangle fan fill, move that center cap vertex up along the Z, and slightly randomize the vertices to get the distortions.

For more complex faceted shapes such as the diamond I'm sure there's algorithms out there for it, but I don't know any by name to help you with google.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply