Options

Game Dev - Unreal 4.13 Out Now!

18485878990100

Posts

  • Options
    RendRend Registered User regular
    edited March 2016
    Machwing wrote: »
    question for folks more aquainted with C# (and Unity) than I:

    -I've got a singleton "Manager" object with a public variable exposed to the Inspector. On start-up, the Manager creates an object (let's call it an Actor) and passes the variable's value as a parameter. I want to be able to update the variable's value in the Inspector and see the change reflected in the Actor's behavior.

    I was initially under the impression that I could pass the variable in by ref, but I can't hold on to the reference this way-- calling "this.value = value" in the Actor's constructor ends up copying the reference by value :/ What I want to do is hold on to the reference--I can do this with a pointer, but that requires me to mark the Actor as unsafe. While the manager technically *could* get deleted without the Actor's knowledge, I know that this won't happen.

    Solutions I've seen:
    - Using the Manager's Update() to reassign the variable to the Actor on every frame. I don't like this b/c A) I'm constantly doing assignments, and B) I want to keep all of an Actor's properties private and use setters/getters for everything inside it. The Manager is the only object that should have reference ties to the Actor.
    - Box the variable as an object, pass it by reference to the Actor on creation, and unbox the variable whenever the Actor needs to read its value. This seems like a reasonable approach right now, but I only want to update the variable at runtime for ease of tweaking during development. I don't want to have to box every variable I add to the Manager during development (apparently a costly thing to do), only to rip all the boxing/unboxing code out when I settle on their values.

    Anybody have any thoughts? Alternate solutions? Should I just mark the dang thing as unsafe and use a pointer

    1. I'm guessing this is a configuration value of some kind, like a move speed or something like that that you're tweaking? Data should only be living in one place. If a class needs to reference data held by another class, it should reference that class to do so.
    2. When you use the term box you're referring to a wrapper which is a pretty commonly used (and not expensive) pattern. Where are you getting the idea that using primitive wrappers is costly, exactly?
    3. There are complex ways of propagating values among arbitrary other classes, specifically the Observer pattern, but I'm pretty sure observer would be total overkill for what you're trying to do.

    Design wise, you have an issue where your manager has both references to actors, and also data that those actors require. One solution that fixes this problem could be to create a separate class that would be a data structure for your public variables, and pass the instance of that data structure to each actor (basically, instead of wrapping each variable individually, just wrap them all together). You won't be changing the data in the manager, but in the data structure instead, but you'd avoid a circular dependency between your manager and actors.

    [edit] DEFINITELY do not use a pointer :p

    Rend on
  • Options
    MachwingMachwing It looks like a harmless old computer, doesn't it? Left in this cave to rot ... or to flower!Registered User regular
    edited March 2016
    1) Sort of. The Actor refreshes some internal properties when a certain amount of time has passed, and the value I'm passing in is a range for one of those properties.
    2) The expense isn't as big of an issue as going back and unwrapping the value(s) once I've settled on them. I'm probably trying to optimize this a lil' early though!

    I was contemplating wrapping all of my manager values in a struct anyway, was avoiding it out of laziness. I suppose I'll just do that!

    If I do go with a struct-- is there a good adapter pattern to setting/getting values in the struct where I can avoid calling "Manager.[Struct].[property]"and call "Manager.[property]" instead?

    Machwing on
    l3icwZV.png
  • Options
    RendRend Registered User regular
    Machwing wrote: »
    1) Sort of. The Actor refreshes some internal properties when a certain amount of time has passed, and the value I'm passing in is a range for one of those properties.
    2) The expense isn't as big of an issue as going back and unwrapping the value(s) once I've settled on them. I'm probably trying to optimize this a lil' early though!

    I was contemplating wrapping all of my manager values in a struct anyway, was avoiding it out of laziness. I suppose I'll just do that!

    Make sure it's not an actual struct: structs are pass-by-value.

  • Options
    RendRend Registered User regular
    Machwing wrote: »
    If I do go with a struct-- is there a good adapter pattern to setting/getting values in the struct where I can avoid calling "Manager.[Struct].[property]"and call "Manager.[property]" instead?

    I'd honestly just pass the instance of the thing to the actors tbh? If you wanna pass manager to your actors, you're describing the Facade pattern pretty much exactly though.

    In C# you can do this via properties like this:
    class Manager{
      public int MyInt
      {
        get { return myDataStructure.myInt; }
        set { myDataStructure.myInt = value; }
      }
    }
    

    Which is... just, so good. I love c#.

  • Options
    MachwingMachwing It looks like a harmless old computer, doesn't it? Left in this cave to rot ... or to flower!Registered User regular
    Next question: When I create an instance of Actor, I start a Coroutine in the manager that waits X seconds, calls refresh_properties() on the actor, and then loops.

    Let's say I want to kill an existing Actor. I need to call StopCoroutine() on the coroutine accessing that Actor beforehand, correct? But I'm not keeping track of these coroutines once I start 'em in the Manager. Do I need to keep a list of Coroutines alongside my list of Actors and kill them by index?

    It seems like a better place to put the Coroutine would be in the Actor class, call it on Start(), and kill it on OnDestroy(), but this would necessitate turning my Actor into a MonoBehavior, which I don't want to do (Actors aren't scene objects).

    l3icwZV.png
  • Options
    RendRend Registered User regular
    Machwing wrote: »
    Next question: When I create an instance of Actor, I start a Coroutine in the manager that waits X seconds, calls refresh_properties() on the actor, and then loops.

    Let's say I want to kill an existing Actor. I need to call StopCoroutine() on the coroutine accessing that Actor beforehand, correct? But I'm not keeping track of these coroutines once I start 'em in the Manager. Do I need to keep a list of Coroutines alongside my list of Actors and kill them by index?

    It seems like a better place to put the Coroutine would be in the Actor class, call it on Start(), and kill it on OnDestroy(), but this would necessitate turning my Actor into a MonoBehavior, which I don't want to do (Actors aren't scene objects).

    If you want to keep your pattern of manager calling update values on actor, you should keep a list of actors, and just update all of them at the same time. If it's important that they not all be updated at the same time (might or might not?), you could add a timer to your actor that looks something like this:
    class Actor{
      float elapsedTime = 0;
      void update(float deltaTime, float totalTime){
        elapsedTime += deltaTime;
        while(elapsedTime >= totalTime){
          elapsedTime -= totalTime;
          //Do a thing
        }
      }
    }
    

  • Options
    MachwingMachwing It looks like a harmless old computer, doesn't it? Left in this cave to rot ... or to flower!Registered User regular
    edited March 2016
    It's important that they not update at the same time (they have random lifetimes). I'll try that out (even though coroutines are so convenient :( ). Thanks for all the help!

    (As for what this is all for: my "Actors" are Gerstner Waves. I'm makin' waterrrrr)
    https://www.youtube.com/watch?v=z9xKc-R69U8

    Machwing on
    l3icwZV.png
  • Options
    RendRend Registered User regular
    Yeah, timers like that are basically a poor-man's coroutine. (They're also a lot easier to test externally so I tend to favor them over coroutines but that's neither here nor there)

    That is pretty freakin cool though :D

  • Options
    agoajagoaj Top Tier One FearRegistered User regular
    edited March 2016
    Just grab the value from your manager. Pass in this to your actor and save that as manager. Then the actor can call manager.MyValue.
    You can also make static methods so anyone can call ManagerClass.GetMyValue(), or a static method that returns the singleton manager like
    var manager = ManagerClass.GetMyManager()
    var myval = manager.MyValue

    If your using accessors, you can have MyValue accessor on Actor return the value from Manager instead of saving it to the Actor.

    agoaj on
    ujav5b9gwj1s.png
  • Options
    RoyceSraphimRoyceSraphim Registered User regular
    edited March 2016
    Anyone have a good theory why this code would stop working once obj_Bosslady would get in range from the left and leave range from the right?
    ///spawner code
    if(distance_to_object(obj_Bosslady) >= 200) //while Bosslady is far enough away
    {
    instance_create(x, y, obj_enemy_secretary); //drop an enemy
    alarm[0] = room_speed * spawnertimer; //reset the timer to a random number
    }
    

    It works fine (albeit a little too fast) while she's far enough away, but stops once she gets close and does not restart. edit: Does not restart if I walk back out of rang on the other side.

    RoyceSraphim on
  • Options
    RendRend Registered User regular
    Anyone have a good theory why this code would stop working once obj_Bosslady would get in range from the left and leave range from the right?
    ///spawner code
    if(distance_to_object(obj_Bosslady) >= 200) //while Bosslady is far enough away
    {
    instance_create(x, y, obj_enemy_secretary); //drop an enemy
    alarm[0] = room_speed * spawnertimer; //reset the timer to a random number
    }
    

    It works fine (albeit a little too fast) while she's far enough away, but stops once she gets close and does not restart. edit: Does not restart if I walk back out of rang on the other side.

    Does it restart if you walk out of range on the side you came in?
    Are you sure distance_to_object is always giving you a positive number?

  • Options
    ThendashThendash Registered User regular
    @RoyceSraphim Is that code running in alarm[0]? If it is, then it's never running again once you are close enough to obj_BossLady because the alarm never gets reset. Switch line 5 with 6 and it should work.

  • Options
    RoyceSraphimRoyceSraphim Registered User regular
    edited March 2016
    Thendash wrote: »
    @RoyceSraphim Is that code running in alarm[0]? If it is, then it's never running again once you are close enough to obj_BossLady because the alarm never gets reset. Switch line 5 with 6 and it should work.

    oh, it is, lets try that.

    Edit: IT WORKED!

    edit: turns out immage_speed = 1 is the sort of thing to freeze your game. Should have paid attention to the text not turning red.

    RoyceSraphim on
  • Options
    LaCabraLaCabra MelbourneRegistered User regular
  • Options
    KhavallKhavall British ColumbiaRegistered User regular
    So I may have messed up, but am I right that if I want to declare a List of objects with lists as arguments in the constructor I have to use the hilarious syntax
    new MarkovCell(new List<int>(new int[]{14, 19}), new List<int>(new int[] {19, 24})),
    

    ?


    Because I spent most of today setting up several Markov chains of depth from 1-4 and boy it really seems like there should be a better way, but nothing else didn't throw errors.

  • Options
    RendRend Registered User regular
    edited March 2016
    Khavall wrote: »
    So I may have messed up, but am I right that if I want to declare a List of objects with lists as arguments in the constructor I have to use the hilarious syntax
    new MarkovCell(new List<int>(new int[]{14, 19}), new List<int>(new int[] {19, 24})),
    

    ?


    Because I spent most of today setting up several Markov chains of depth from 1-4 and boy it really seems like there should be a better way, but nothing else didn't throw errors.

    Without trying to guess to much at your implementation, you can make a static method that generates a list given an arbitrary set of parameters, like this:
    
    public static List<int> intListFromParams(params int[] intArray){
      return intArray.ToList();
    }
    
    public void getSomeLists(){
      List<int> upToThree = intListFromParams(1, 2, 3);
      List<int> upToSix = intListFromParams(1, 2, 3, 4, 5, 6);
      List<int> justTheEvens = intListFromParams(2, 4, 6, 8);
    }
    
    

    [edit] You can also be more generic about it by using Object instead of int, and passing in a type to cast it to, but this sounds like more of a one-off solution

    Rend on
  • Options
    amnesiasoftamnesiasoft Thick Creamy Furry Registered User regular
    I'd be surprised if List doesn't already have a constructor that does that. I haven't used C# in a while, can it not infer the type too? So you could have something like List(1, 2)?

    List might also have a static method you can use instead.

    steam_sig.png
  • Options
    RendRend Registered User regular
    edited March 2016
    I'd be surprised if List doesn't already have a constructor that does that. I haven't used C# in a while, can it not infer the type too? So you could have something like List(1, 2)?

    List might also have a static method you can use instead.

    I'm pretty sure generic types in c# have to be explicitly declared, and I don't think List<T> has a constructor or static method which does that

    Which is definitely surprising because when I went to go look in replying to that post, that's exactly what I expected to find, but then did not.

    The closest list has that I can see is List<T>(IEnumerable<T>) which is what he's using in the example above (since arrays implement IEnumerable), but List<T> specifically doesn't have a constructor with the params keyword.

    Rend on
  • Options
    KhavallKhavall British ColumbiaRegistered User regular
    edited March 2016
    Yeah it's weird. I could've done it with a void too, but since those values are just hardcoded in I figured I could put it in the constructor and be happy, but I had to do that weird new List<int> new int[]{numbers} thing to get it to actually set up in the constructor.

    it's not a big deal anymore, but boy was I frustrated yesterday setting up about 70-80 of those nodes and having to copy-paste that stupid line 80 times. And the numbers are all set, they're not derived from anything, so I had to be very specific about each cell in the Markov chains.

    Khavall on
  • Options
    RendRend Registered User regular
    Oof. At that point I probably would have put it into a resource asset and read the inputs from there instead. 80 nearly identical lines of initialization is a lot.

  • Options
    RoyceSraphimRoyceSraphim Registered User regular
    edited March 2016
    Anyone got an idiots guide to Unity? I'm thinking ahead after I finish Kung Fu Office lady....and figure out how to code a boss.

    edit: Just realized I wrote out my facing code twice in my basic enemy parent.

    RoyceSraphim on
  • Options
    amnesiasoftamnesiasoft Thick Creamy Furry Registered User regular
    Rend wrote: »
    I'd be surprised if List doesn't already have a constructor that does that. I haven't used C# in a while, can it not infer the type too? So you could have something like List(1, 2)?

    List might also have a static method you can use instead.

    I'm pretty sure generic types in c# have to be explicitly declared, and I don't think List<T> has a constructor or static method which does that

    Which is definitely surprising because when I went to go look in replying to that post, that's exactly what I expected to find, but then did not.

    The closest list has that I can see is List<T>(IEnumerable<T>) which is what he's using in the example above (since arrays implement IEnumerable), but List<T> specifically doesn't have a constructor with the params keyword.
    Yeah, I tried searching on my phone before saying anything, but MSDN wasn't loading.

    I've just been that weirdo using D which has type inferencing for templates so calling TemplateFunction<T>(T, string) would magically fill T with the type used for the first argument.

    Oh well.

    steam_sig.png
  • Options
    RoyceSraphimRoyceSraphim Registered User regular
    I've crashed gamemaker trying to edit out my spr_bosslady_punch's arm.

    I restarted and managed to get my boss for the first level flying back when hit, although facing the wrong direction.

    I also had the brilliant idea to limit movement to when !(attacking) and it turns out you can't actually finish the level.

    I've also come to appreciate this view as useful for debugging.
    w8nVj3Q.png

  • Options
    kaceypkaceyp we stayed bright as lightning we sang loud as thunderRegistered User regular
    Anyone got an idiots guide to Unity? I'm thinking ahead after I finish Kung Fu Office lady....and figure out how to code a boss.

    edit: Just realized I wrote out my facing code twice in my basic enemy parent.

    I'm not sure about a singular guide, but in general when I started I found both YouTube tutorials and Unity Answers to be incredibly helpful. I think I tend to favor Unity Answers for troubleshooting, and YouTube (or wherever) vids for more in-depth stuff. I really liked the BurgZerg Arcade videos on YouTube, and Brackeys is pretty good. Keep in mind the dates on all that stuff -- a lot of specific details on older stuff might be outdated now, but I'd imagine it would still be helpful for learning your way around the engine.

    There's also a set of tutorials on the Unity site itself, most of which I haven't looked at but seem pretty good.

  • Options
    MachwingMachwing It looks like a harmless old computer, doesn't it? Left in this cave to rot ... or to flower!Registered User regular
    edited March 2016
    heeeeey gamedev thread, here's a fun Unity question:

    I want my water shader to be aware of "local wave sets" in the game space. That is, I want my vertex shader to blend between one set of gerstner waves and another set based on the world position of the verts, and I want to define the region affected by a wave set in a complex manner (more than just a sphere or box of influence). I'm not sure what the best way of going about defining the regions is. Options I'm considering:

    - Use scene objects to define wave set regions. I.E. object "Waveset_1" has children "influence_sphere01", "influence_box02", whose bounds combine to define the region where waveset 1's waves should be used.
    Pros: super easy to author regions! Just add geo to the scene.
    Cons: EXPENSIVE AS FUUUUUUCK. Way too much communicating between the CPU and GPU (would need to do distance checking against possibly dozens of objects for every single vertex on my water geo)

    - Instead of using spheres of influence, author a level-sized alpha mask for each wave set. I could define any shape for the wave set's influence region, paint falloff in, etc.
    Pros: don't need to hit the CPU once the mask(s) are loaded into memory, arbitrary shapes easy to define.
    Cons: resolution might be a factor for large levels, limited to 2D regions, authoring and iterating on the masks would be a huge pain.

    - Dream option: define regions in the editor with actors, but bake that information down at build-time to a mask and pass that to the GPU!
    Pros: best of both worlds! Ease of authoring + performance. Still limited to 2D regions, but that's probably not a big deal for...an ocean surface
    Cons: man writing tools is haaaard

    Machwing on
    l3icwZV.png
  • Options
    MachwingMachwing It looks like a harmless old computer, doesn't it? Left in this cave to rot ... or to flower!Registered User regular
    fuck it I'm going with option 3

    I'm NBA livin' da dream

    l3icwZV.png
  • Options
    RoyceSraphimRoyceSraphim Registered User regular
    Unity for 3d, game maker for 2d is the rule, right?

  • Options
    GlalGlal AiredaleRegistered User regular
    edited March 2016
    Unity does 2d just fine, just use ortho projection and stick your 2d textures on the sides of boxes to get collision and physics going (or better, have one box/plane for the texture in the front and then a different object for collision that it's attached to). You can set up a 1:1 pixel ratio camera without too much trouble if you need retro pixel art.

    Glal on
  • Options
    Houk the NamebringerHouk the Namebringer Nipples The EchidnaRegistered User regular
    As someone with no coding/computer science background and who recently has been spending time with both Game Maker and Unity, my experience is: Game Maker's advantage is that it's a little easier to understand the basics and get something up and running, and if your game system isn't particularly complicated, it can be easier to arrive at a finished product. But Unity is way more flexible, and the variety of assets and resources makes it a more powerful long-term tool for 2D just as much as for 3D.

  • Options
    GlalGlal AiredaleRegistered User regular
    Also, if you intend for your game to be multiplatform Game Maker is more limited in that respect.

  • Options
    RoyceSraphimRoyceSraphim Registered User regular
    So get the Prototype up and running to test my theory in game maker then construct the final product in unity.

  • Options
    LaCabraLaCabra MelbourneRegistered User regular
    Or you could diiiive into ue4

  • Options
    GlalGlal AiredaleRegistered User regular
    If you're doing 2d in UE4 and are trying to get the visuals to look Just Right (1:1 pixel ratio for pixel art, displayed colours matching the art assets) expect to spend a lot of time hitting walls and finding ways around them.
    Mechanically UE4 provides a lot of useful tools for 2d, visually it's a struggle the entire way to get the engine to stop trying to "help".

  • Options
    LaCabraLaCabra MelbourneRegistered User regular
    Yeah I haven't tried the actual 2D stuff in Unreal, but as long as we're talking about just throwing an orthographic camera in a 3D scene and calling it 2D thought I'd suggest it :)

  • Options
    GlalGlal AiredaleRegistered User regular
    Between Paper2d, sprite flipbooks and tilemaps the engine actually provides a lot of really useful mechanical functionality for 2d games, but as far as actual scene rendering goes it's clear where their priorities lie. Like, even if the scene is unlit there's still forced post-processing turned on and you need to manually go override parts of it, just to get the colours mostly right (I have not managed to get it 100% myself, reading up on it it requires digging into their PP code and applying reverse-operations on the stuff that cannot be turned off).
    You can tweak the ortho camera and your texture units to get 1:1 pixel ratio, but it's resolution-dependent, so if the person is running a different resolution whoops, your pixels are off. You can probably have an init call that does the required calculation and setting tweaks for you when resolution changes, but I've not needed it on my project, so haven't bothered.
    The tilemaps allow you to create levels with multiple layers and different collision properties, so you can do neat stuff like have a middle layer with which your characters collide, with a foreground layer and a background layer, all in one object. Super useful... unless both your sprite and your tiles use alpha, in which case UE4 will Z-sort the entire tilemap as one object for speed purposes, meaning your non-tilemap sprites will either end up rendered either in front or behind the entire map, even though they're technically in the middle of it.

    It's lots of weird gotchas like that.

  • Options
    LaCabraLaCabra MelbourneRegistered User regular
    You can always just turn post processing off entirely by invoking the "show postprocess" console command although that is clearly not ideal

  • Options
    Houk the NamebringerHouk the Namebringer Nipples The EchidnaRegistered User regular
    Also, if you're new to game dev and just starting to familiarize yourself with different game engines, all of that is probably well beyond your current skill level.

  • Options
    RendRend Registered User regular
    I've been using Unity2D for awhile now and I find it works well and is very flexible.

  • Options
    IzzimachIzzimach Fighter/Mage/Chef Registered User regular

    I built up a bug using physics & rigid bodies and now you can climb it. So that's got sort of a SotC vibe going. Now I'm trying to figure out how to make procedural 3D buildings and giant climbable robots. But there aren't a lot of resources for that kind of thing, so I guess I'm just going to have to flail around for a while. Most of the building generators I've found are meant for populating a big cityscape or whatever. And of course I can't find anything about generating giant robots :biggrin:

    3r8qSQd.jpg

    I mean this STRANGETHINK person is making some awesome looking structures but I'm not sure they are very good for platforming.

    Cek_DlrW4AMEjbQ.jpg

  • Options
    UselesswarriorUselesswarrior Registered User regular
    edited April 2016
    People who know me as a long time member of the forums may have noticed that I haven't been very active lately. Well it's been because I've been working on my first game and I haven't had much time for anything else.

    Behold, I emerge from the code mines with some gifs (well webms) of my game!

    Death Explosions! https://gfycat.com/ThirdSmartHairstreakbutterfly
    Deadly Birds! https://gfycat.com/GargantuanSelfassuredGalapagoshawk
    Old Timey Menus! https://gfycat.com/FavorableIncomparableBluebottle

    And since we can't embed GFYCat links here is a lower res fat gif:

    ComplicatedSpryAlbertosaurus.gif

    This game dev shit is a lot of work. Almost there though, just lots of polishing to go.

    Uselesswarrior on
    Hey I made a game, check it out @ http://ifallingrobot.com/. (Or don't, your call)
Sign In or Register to comment.