As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
We're funding a new Acquisitions Incorporated series on Kickstarter right now! Check it out at https://www.kickstarter.com/projects/pennyarcade/acquisitions-incorporated-the-series-2

Game Dev - Unreal 4.13 Out Now!

18081838586100

Posts

  • LaCabraLaCabra MelbourneRegistered User regular
    that is sick

    KoopahTroopah
  • HallowedFaithHallowedFaith Call me Cloud. Registered User regular
    edited February 2016
    @LaCabra you should quote it in your post so it can be top'd - it is indeed sick.

    HallowedFaith on
    I'm making video games. DesignBy.Cloud
  • ZekZek Registered User regular
    Decided to set myself a more achievable goal and make something simple, with a written design doc to define the scope. Started on an RPG battler in the vein of Soda Dungeon or Galaxy of Heroes, with a minimalist UI (mouse cursor not recorded). Pretty happy with how easy it was to get the combat fundamentals in place. FF provides a limitless source of placeholder assets obviously:

    https://www.youtube.com/watch?v=2eCkyny52C8

    DarkMechaKoopahTroopahHallowedFaith
  • IzzimachIzzimach Fighter/Mage/Chef Registered User regular
    Does UE4 support gamepad control of GUI widgets (UMG)? I see some stuff about widget focus and gamepad input but it's not obvious that everything "just works". What videos I can find usually just grab gamepad events and manage the UI state by hand. Is this basically how it's done at the moment?

  • VicVic Registered User regular
    edited February 2016
    I've recently looked back into Unity development, and god damn is this utterly intimidating. I know a bit of basic code, I know exactly what I want to do, but I just have no idea how to even read the help pages for the kind of scripts that Unity works with, let alone integrate them into my project. Game maker was much easier to work with, but too limiting, buggy, and had utterly unhelpful error report messages.

    I should probably start from the absolute basics, but I have yet to find a tutorial series that seems to cover any of the stuff I actually want to do without relying on me already being an intermediate unity programmer.

    Vic on
  • RendRend Registered User regular
    Vic wrote: »
    I've recently looked back into Unity development, and god damn is this utterly intimidating. I know a bit of basic code, I know exactly what I want to do, but I just have no idea how to even read the help pages for the kind of scripts that Unity works with, let alone integrate them into my project. Game maker was much easier to work with, but too limiting, buggy, and had utterly unhelpful error report messages.

    I should probably start from the absolute basics, but I have yet to find a tutorial series that seems to cover any of the stuff I actually want to do without relying on me already being an intermediate unity programmer.

    I agree that you should start basic, but when you say something like "start from the absolute basics" it is often due to it intimidating you (as you mentioned!) more than it is inaccessibility of the matter itself.

    Can you identify, like, a few key basic interactions/behaviors that confuse you? A few things that you think if you can nail quickly that will help you to understand the whole system better? If so, what are they?

  • VicVic Registered User regular
    edited February 2016
    Rend wrote: »
    Vic wrote: »
    I've recently looked back into Unity development, and god damn is this utterly intimidating. I know a bit of basic code, I know exactly what I want to do, but I just have no idea how to even read the help pages for the kind of scripts that Unity works with, let alone integrate them into my project. Game maker was much easier to work with, but too limiting, buggy, and had utterly unhelpful error report messages.

    I should probably start from the absolute basics, but I have yet to find a tutorial series that seems to cover any of the stuff I actually want to do without relying on me already being an intermediate unity programmer.

    I agree that you should start basic, but when you say something like "start from the absolute basics" it is often due to it intimidating you (as you mentioned!) more than it is inaccessibility of the matter itself.

    Can you identify, like, a few key basic interactions/behaviors that confuse you? A few things that you think if you can nail quickly that will help you to understand the whole system better? If so, what are they?

    After sitting down and trying to put my problems into words I think I managed to get a little closer to understanding how this stuff fits together. That said, I have still only barely gotten a single rudimentary script to work, and I basically copied all of it from a webpage.

    I guess I find the idea of assigning a variable inside of a script first, and then drag-dropping a gameobject into it to assign its corresponding element to that variable a kind of ass-backwards way of doing things, which was a large part of my problem.

    I still can't get this thrice-damned button to work though. The script I am using is as follows:
    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;
    
    public class unitychrist : MonoBehaviour {
        public Text testtext;
        void Start() {
        }	
    	// Update is called once per frame
    	void Update () {	
    	}
        public void onClick()
        {
            testtext.text = "Why isnt this working";
        }
    }
    

    I have dragged and dropped the text gameobject into the testtext slot (and confirmed that my setup works by successfully editing the text using the void Start function). This script is attached to an otherwise empty gameobject, which I dragged and dropped into the On Click slot of my button, then selected the function onClick in the dropdown list.

    Still nothing.

    Vic on
  • RendRend Registered User regular
    Okay that's a pretty good place to start. Few things.

    1. You should use public + unity editor assignment in situations where that's the right way to do things, mainly this is to say, when you want to be able to edit stuff in the editor as opposed to in code. It's easier to do many things in the editor, which is why this pattern is so prevalent. However, you don't have to do this with everything.
    2. Just as a point of order, you're DECLARING the variable in the script and ASSIGNING it in the editor. But that's just me nitpicking :p
    3. Try putting the script onto the button instead. That shouldn't fix anything but it's better than having your script living in a random object somewhere. Then you can drag the button object into its own slot, and select the function from there.
    4. Do you have an event system? When you make a canvas, you should have an event system spawn automatically, but an event system is required for any click events in the UI layer. (And indeed you should utilize it for all your clicks)

  • VicVic Registered User regular
    Rend wrote: »
    Okay that's a pretty good place to start. Few things.

    1. You should use public + unity editor assignment in situations where that's the right way to do things, mainly this is to say, when you want to be able to edit stuff in the editor as opposed to in code. It's easier to do many things in the editor, which is why this pattern is so prevalent. However, you don't have to do this with everything.
    2. Just as a point of order, you're DECLARING the variable in the script and ASSIGNING it in the editor. But that's just me nitpicking :p
    3. Try putting the script onto the button instead. That shouldn't fix anything but it's better than having your script living in a random object somewhere. Then you can drag the button object into its own slot, and select the function from there.
    4. Do you have an event system? When you make a canvas, you should have an event system spawn automatically, but an event system is required for any click events in the UI layer. (And indeed you should utilize it for all your clicks)

    Well, that explains that, thanks a lot! In my defence I'm pretty sure I struggled with this problem for more than an hour with the event system intact, and I have no idea how I managed to delete it, but simply recreating it seems to have done the trick.

    Thanks for the tip on attaching the script to the button by the way, that should make things a fair bit neater.

  • RendRend Registered User regular
    Vic wrote: »
    Rend wrote: »
    Okay that's a pretty good place to start. Few things.

    1. You should use public + unity editor assignment in situations where that's the right way to do things, mainly this is to say, when you want to be able to edit stuff in the editor as opposed to in code. It's easier to do many things in the editor, which is why this pattern is so prevalent. However, you don't have to do this with everything.
    2. Just as a point of order, you're DECLARING the variable in the script and ASSIGNING it in the editor. But that's just me nitpicking :p
    3. Try putting the script onto the button instead. That shouldn't fix anything but it's better than having your script living in a random object somewhere. Then you can drag the button object into its own slot, and select the function from there.
    4. Do you have an event system? When you make a canvas, you should have an event system spawn automatically, but an event system is required for any click events in the UI layer. (And indeed you should utilize it for all your clicks)

    Well, that explains that, thanks a lot! In my defence I'm pretty sure I struggled with this problem for more than an hour with the event system intact, and I have no idea how I managed to delete it, but simply recreating it seems to have done the trick.

    Thanks for the tip on attaching the script to the button by the way, that should make things a fair bit neater.

    Yeah for sure! So in general a pretty good control flow is to make it so that the button always calls a local onClick function which is in the panel containing the button, then have a variable in that script in which you set another object to transfer control to.

    It might look like:
    Canvas
      MyPanelWithButtons
        StartButton
        QuitButton
    
    class MyPanelWithButtons {
      public GameStateThing gameStateThing;
      public void onClickStart(){
        gameStateThing.start();
      }
      public void onClickQuit(){
        gameStateThing.quit();
      }
    }
    

    When you make a prefab out of this stuff, relationships you establish in the unit editor between objects (like dragging a panel object onto a child button's onClick object to select one of those two example functions) will persist as long as both objects are part of the prefab. Or, to say that another way, making a prefab out of an object breaks all relationships to its parent and siblings.

    DarkMecha
  • GlalGlal AiredaleRegistered User regular
    My monster. My beautiful monster.
    unreal_animation_state_machine.png

    DarkMecha
  • KoopahTroopahKoopahTroopah The koopas, the troopas. Philadelphia, PARegistered User regular
    edited February 2016
    Not sure if you guys are interested, but Vulkan was released today! It's a graphics API similar to OpenGL that focuses more on efficiency in cross-platforms. It was used in The Talos Principle.

    KoopahTroopah on
    Ed GrubermanKashaarGlal
  • DarkMechaDarkMecha The Outer SpaceRegistered User regular
    Vic wrote: »
    Rend wrote: »
    Okay that's a pretty good place to start. Few things.

    1. You should use public + unity editor assignment in situations where that's the right way to do things, mainly this is to say, when you want to be able to edit stuff in the editor as opposed to in code. It's easier to do many things in the editor, which is why this pattern is so prevalent. However, you don't have to do this with everything.
    2. Just as a point of order, you're DECLARING the variable in the script and ASSIGNING it in the editor. But that's just me nitpicking :p
    3. Try putting the script onto the button instead. That shouldn't fix anything but it's better than having your script living in a random object somewhere. Then you can drag the button object into its own slot, and select the function from there.
    4. Do you have an event system? When you make a canvas, you should have an event system spawn automatically, but an event system is required for any click events in the UI layer. (And indeed you should utilize it for all your clicks)

    Well, that explains that, thanks a lot! In my defence I'm pretty sure I struggled with this problem for more than an hour with the event system intact, and I have no idea how I managed to delete it, but simply recreating it seems to have done the trick.

    Thanks for the tip on attaching the script to the button by the way, that should make things a fair bit neater.

    Other useful UI stuff that might help you:

    If you want to make UI panels show or hide you can just store them as a GameObject then do a myUIThingy.SetActive(true);
    You can make non-linear progress bar type things with a UI Image set to Fill and then radial or whatever you want. Go go Ironman style UI stuff!
    If your UI text looks blurry one way to make it as sharp as you like is to set the scale to like .25 and then jack up the font size. Weird I know and there may be a better way to do it but this one always gets me the results I want.
    To make sure your UI scales based on screen ratio and what not make sure to set the anchors to keep them where you want (like bottom right corner ect). Also if you are using UI Scale Mode: Scale With Screen Size (the one I tend to prefer), make sure you set the Reference Resolution to be what you think most people will be using. I tend to design UI for 1080p with the UI images being high enough res that they can scale up abit beyond that too.

    Unsolicited Unity advice GO!

    Steam Profile | My Art | NID: DarkMecha (SW-4787-9571-8977) | PSN: DarkMecha
    Rend
  • KashaarKashaar Low OrbitRegistered User regular
    Glal wrote: »
    My monster. My beautiful monster.
    unreal_animation_state_machine.png

    That's cute! (And well-commented.)

    Indie Dev Blog | Twitter | Steam
    Unreal Engine 4 Developers Community.

    I'm working on a cute little video game! Here's a link for you.
    Calica
  • LaCabraLaCabra MelbourneRegistered User regular
    Glal wrote: »
    My monster. My beautiful monster.
    unreal_animation_state_machine.png

    not sure what you're doin but might be worth looking into animblueprint state machines

    Kashaar
  • GlalGlal AiredaleRegistered User regular
    edited February 2016
    Can you use those with flipbooks now? The Unreal video tutorial for Paper2d is terribly old (from its beta in mid-2014) and it stated you cannot use animation state machines with flipbooks.

    [edit] Okay, before I spend an entire evening comparing a million settings side by side- in the demo 2d Blueprint Platformer the character's collision capsule appears to behave like a box (which is what you'd want for pretty much any platformer that isn't centered on physics). However, with my own PaperCharacter class, it behaves like a capsule, which is... well, shit and worthless and ick.

    unreal_bp_collision_capsule.png

    What's the setting that makes the difference here? I'd rather not have another collision box on top of the capsule, who knows what side effect that might have on the API returns (just off the top of my head, I can see the Landing return stop working, for example).

    [edit2] Found it! There's a tick for "Use Flat Base For Floor Checks" in the character blueprint -> CharacterMovement component defaults section -> Character Movement: Walking -> expanded.

    Glal on
  • VicVic Registered User regular
    edited February 2016
    DarkMecha wrote: »
    Vic wrote: »
    Rend wrote: »
    Okay that's a pretty good place to start. Few things.

    1. You should use public + unity editor assignment in situations where that's the right way to do things, mainly this is to say, when you want to be able to edit stuff in the editor as opposed to in code. It's easier to do many things in the editor, which is why this pattern is so prevalent. However, you don't have to do this with everything.
    2. Just as a point of order, you're DECLARING the variable in the script and ASSIGNING it in the editor. But that's just me nitpicking :p
    3. Try putting the script onto the button instead. That shouldn't fix anything but it's better than having your script living in a random object somewhere. Then you can drag the button object into its own slot, and select the function from there.
    4. Do you have an event system? When you make a canvas, you should have an event system spawn automatically, but an event system is required for any click events in the UI layer. (And indeed you should utilize it for all your clicks)

    Well, that explains that, thanks a lot! In my defence I'm pretty sure I struggled with this problem for more than an hour with the event system intact, and I have no idea how I managed to delete it, but simply recreating it seems to have done the trick.

    Thanks for the tip on attaching the script to the button by the way, that should make things a fair bit neater.

    Other useful UI stuff that might help you:

    If you want to make UI panels show or hide you can just store them as a GameObject then do a myUIThingy.SetActive(true);
    You can make non-linear progress bar type things with a UI Image set to Fill and then radial or whatever you want. Go go Ironman style UI stuff!
    If your UI text looks blurry one way to make it as sharp as you like is to set the scale to like .25 and then jack up the font size. Weird I know and there may be a better way to do it but this one always gets me the results I want.
    To make sure your UI scales based on screen ratio and what not make sure to set the anchors to keep them where you want (like bottom right corner ect). Also if you are using UI Scale Mode: Scale With Screen Size (the one I tend to prefer), make sure you set the Reference Resolution to be what you think most people will be using. I tend to design UI for 1080p with the UI images being high enough res that they can scale up abit beyond that too.

    Unsolicited Unity advice GO!

    It is appreciated, though it may take time before I know enough to actually understand how to implement that stuff.

    I've made a bit of progress since last time, but my current problem is that I'm not good enough at calling on variables without using the drag-drop interface.

    As an example, I need to change the text element of a gameobject. I want to be able to copy this script around to different gameobjects, so as to not have to drag and drop to assign stuff I want to use the Find function to point to the right gameobject, then the GetComponent function to access the right component. I just don't quite understand how to do that.

    The find function seems straightforward enough.
    textgameobject = GameObject.Find("textgameobject");
    

    I'm also assuming I can slap "GameObject " at the front of that line to avoid having to declare it earlier on in the code (though maybe I should anyway for efficiency?)

    The problem comes with the getcomponent code. The example code from the wiki looks like this:
    void Start () {
        Rigidbody rb = GetComponent<Rigidbody>();
    }
    

    How does that code know which GameObject to extract that component from? Is it the GameObject the script is assigned to, and in that case how can I target it towards another one? Can I extract a component from another GameObject without first assigning that GameObject in this script?

    Vic on
  • KhavallKhavall British ColumbiaRegistered User regular
    edited February 2016
    Vic wrote: »
    DarkMecha wrote: »
    Vic wrote: »
    Rend wrote: »
    Okay that's a pretty good place to start. Few things.

    1. You should use public + unity editor assignment in situations where that's the right way to do things, mainly this is to say, when you want to be able to edit stuff in the editor as opposed to in code. It's easier to do many things in the editor, which is why this pattern is so prevalent. However, you don't have to do this with everything.
    2. Just as a point of order, you're DECLARING the variable in the script and ASSIGNING it in the editor. But that's just me nitpicking :p
    3. Try putting the script onto the button instead. That shouldn't fix anything but it's better than having your script living in a random object somewhere. Then you can drag the button object into its own slot, and select the function from there.
    4. Do you have an event system? When you make a canvas, you should have an event system spawn automatically, but an event system is required for any click events in the UI layer. (And indeed you should utilize it for all your clicks)

    Well, that explains that, thanks a lot! In my defence I'm pretty sure I struggled with this problem for more than an hour with the event system intact, and I have no idea how I managed to delete it, but simply recreating it seems to have done the trick.

    Thanks for the tip on attaching the script to the button by the way, that should make things a fair bit neater.

    Other useful UI stuff that might help you:

    If you want to make UI panels show or hide you can just store them as a GameObject then do a myUIThingy.SetActive(true);
    You can make non-linear progress bar type things with a UI Image set to Fill and then radial or whatever you want. Go go Ironman style UI stuff!
    If your UI text looks blurry one way to make it as sharp as you like is to set the scale to like .25 and then jack up the font size. Weird I know and there may be a better way to do it but this one always gets me the results I want.
    To make sure your UI scales based on screen ratio and what not make sure to set the anchors to keep them where you want (like bottom right corner ect). Also if you are using UI Scale Mode: Scale With Screen Size (the one I tend to prefer), make sure you set the Reference Resolution to be what you think most people will be using. I tend to design UI for 1080p with the UI images being high enough res that they can scale up abit beyond that too.

    Unsolicited Unity advice GO!

    It is appreciated, though it may take time before I know enough to actually understand how to implement that stuff.

    I've made a bit of progress since last time, but my current problem is that I'm not good enough at calling on variables without using the drag-drop interface.

    As an example, I need to change the text element of a gameobject. I want to be able to copy this script around to different gameobjects, so as to not have to drag and drop to assign stuff I want to use the Find function to point to the right gameobject, then the GetComponent function to access the right component. I just don't quite understand how to do that.

    The find function seems straightforward enough.
    textgameobject = GameObject.Find("textgameobject");
    

    I'm also assuming I can slap "GameObject " at the front of that line to avoid having to declare it earlier on in the code (though maybe I should anyway for efficiency?)

    The problem comes with the getcomponent code. The example code from the wiki looks like this:
    void Start () {
        Rigidbody rb = GetComponent<Rigidbody>();
    }
    

    How does that code know which GameObject to extract that component from? Is it the GameObject the script is assigned to, and in that case how can I target it towards another one? Can I extract a component from another GameObject without first assigning that GameObject in this script?

    It naturally points to the object that the script is attached to(though I don't even know if it actually works like that, I always have it as gameObject.GetComponent<Rigidbody>(); so that I'm specifically saying "this object's rigidbody component". That might actually be unnecessary I guess)

    If you want to point at another object, you need to have a reference to that object.

    for example:
    public GameObject thisObject;
    
    void start(){
         Rigidbody rb = thisObject.GetComponent<Rigidbody>();
    }
    
    which would allow you to drag and drop an object in the inspector, if it's in the scene.

    Alternatingly, you can do stuff like
    void start(){
         GameObject thisObject = GameObject.Find("objectIwantToPointTo")
         Rigidbody rb = thisObject.GetComponent<Rigidbody>();
    }
    

    Or the hilarious "Rigidbody rb = GameObject.Find("objectIWantToPointTo").GetComponent<Rigidbody>();", which is the same thing but ugly.

    You could also do something where the object controls itself, so you don't need to muck about with getting components of it, if you're going to be changing several things and don't want to have a billion public variables, for instance.

    Have something where if you wanted to change text, position, and some other variable:
    //This is the Manager script
    void ObjectManipulate(){
         GameObject thisObject = GameObject.Find("ObjectIWantToPointTo")
         ObjectScript objectScript = thisObject.GetComponent<ObjectScript>();
         objectScript.ChangeValues("New Text", new Vector3(1, 1, 1), 5);
    }
    
    //And this is the Object's script
    private string myText;
    private int myValue;
    
    
    public void ChangeValues(string text, Vector3 position, int value)
    {
         myText = text;
         myValue = value;
         
         Rigidbody rb = GetComponent<Rigidbody>();
         rb.transform.position = position;
    }
    

    That way, if you have objects that all behave the same general way and just want to manipulate stuff, the objects can self-reference and deal with all their own components, and whatever is giving them values can just tell them the values. This way is better if you want to change a butt-ton of stuff in an object. Or if there's behaviour based on the changing of those values that would make more sense to put in the object itself.

    Khavall on
    Vic
  • VicVic Registered User regular
    That's exactly what I needed, thanks! I'm really not used to how flagrantly Unity (or I guess C#) mixes classes, components, variables and functions by just putting a dot sign between them, but I imagine that will pass.

  • HallowedFaithHallowedFaith Call me Cloud. Registered User regular
    edited February 2016
    Still working on my 'puzzle' game. It got a final name and a web demo with 10 levels and a few of the items goes out next week. Doing audio testing right now for demo. A lot of the grid animations are still being fleshed out. Couple of items just have generic placeholder effects.

    https://www.youtube.com/watch?v=9Ou7AiYCQSA

    HallowedFaith on
    I'm making video games. DesignBy.Cloud
    KoopahTroopahGlalMNC DoverIanatorkaceyp
  • KhavallKhavall British ColumbiaRegistered User regular
    edited February 2016
    Ok, I've got a problem that I've solved, but probably in a dumb way. And it's frustrating that the way it should work isn't working, especially since if I'm getting something wrong here and not seeing it it'll tear the whole thing down.
    Basic setup is that I've got 6 2d Arrays of ints. Then I have a jagged array that holds those 2d arrays, so I've got
    int[,] mel1 = new int[,]{
         {24, 16},
         {22, 4},
         {21, 4},
         {19, 4}
    };
    int[,] rhy1 = new int[,]{
        {12, 4},
        {12, 1},
        {12, 1},
        {19, 2}
    };
    
    and etcetera, on to 6 lists.

    Then I have
    int[][,] noteLists;
    
    //And in a void that is called on Awake from the GameManager
    noteLists = new int[][,]
    {
    mel1,
    mel2,
    rhy1,
    rhy2,
    bass1,
    bass2
    };
    

    This seems to be working.
    Then I have an array that holds the current index of the lists, which advances when the second number of each element's number of sixteenths(which advance at a rate determined by the tempo) has passed

    Basically this is so the lists can advance synchronized in the music, but different note lengths can be used. The list of each tower's current note and rhythmic value is held in the currentNote int[,] Then when the tower is ready to shoot, it plays the note(the first index of the list in the tower's index), and sets the delay before it fires again to its fire rate times the notes length.

    The long and short of it is that I'm trying to get a system where behind the scenes the music is always playing together, but the towers, since they fire slowly before being upgraded, just take whichever note they would be playing if they were playing the music at its intended final tempo, and then have a proportional rhythm. This way, even if they're upgraded at a time that isn't in the beat, or built at a time that isn't in the beat, or there's no enemy so they don't fire exactly synchronized, the music will remain synchronized and won't slowly fall apart.

    So the problem lies in when I'm trying to set the currentNote for each tower, and while I have it seemingly working, it feels like I shouldn't have to do one of the steps I'm doing to get it to work.

    So I've got:
    for(int i=0; i<6; i++) //for each list
    {
         if(totalSixteenth>nextNote[i]){  //if the total number of sixteenths that have passed is equal to or greater than the number of sixteenths that need to pass before the next note is played, for this instrument
         {
              indices[i]++; //Advances the list of the indeces, which keeps track of where in each Musical line the instrument is in
              if(indices[i]>=noteLists[i].Length){indices[i]=0;} //repeats line if the end has been reached
    
              //And here's the shitty part:
               currentNote[i,0] = noteLists[i][indices[i],0];
               currentNote[i,1] = noteLists[i][indices[i],1];   //Sets the list values, but there's no reason, as far as I can tell, that I should have to do both of these.
               nextNote[i]+=noteLists[i][indices[i],1];
         }
    }
    


    It's a small thing, but should I in theory just be able to say that currentNote=noteLists[indices];? I'm asking for an int[] and it should be returning and int[] but for some reason it's saying that it's expecting a different number of elements.

    Khavall on
  • RendRend Registered User regular
    edited February 2016
    Short answer: Don't ever use arrays, unless you absolutely need to. Use objects instead.

    Long answer: Something like this.
    class Note{
      public Interface NoteCallback{
        void noteFinished();
      }
    
      public int length; //In 16th notes
      private int position = 0;
      private NoteCallback callback;
    
      public Note(NoteCallback callback, int length){
        this.callback = callback;
        this.length = length;
      }
      
      public void advance(){
        position++;
        if(position >= length){
          callback.noteFinished();
        }
      }
    }
    
    class NoteList : NoteCallback {
      public Queue<Note> notes;
    
      public NoteList(){
        notes = new Queue<Note>();
      } 
    
      public void addNote(int length){
        notes.enqueue(new Note(this, length));
      }
    
      public void advance(){
        notes.peek().advance();
      }
    
      public void noteFinished(){
        notes.dequeue();
      }
    }
    

    Rend on
  • RendRend Registered User regular
    edited February 2016
    Important notes:
    1. The note list itself keeps its own position, it does not need to be known outside. Currently you have one class which keeps track of all the current positions of each of the parts, but that's a code smell.
    2. You can have your manager class keep multiple notelists for each of your parts or what have you
    3. instead of using for(int i = 0; i < length; i++) you should use foreach(NoteList list in Lists)
    4. Arrays are bad. You should only use them when ABSOLUTELY NECESSARY. Collections are almost always superior to arrays unless you are dealing with sub-millisecond levels of optimization.
    5. Use interfaces. Cool guys use interfaces.

    [edit] Also I just kind of threw public vs private in there so don't pay attention to that

    Rend on
  • RendRend Registered User regular
    Also that architecture can easily be modified such that you can create note lists that represent riffs, and can repeat themselves instead of dequeue'ing the notes and throwing them away.

    Which probably is something you would find immensely useful.

  • KhavallKhavall British ColumbiaRegistered User regular
    Ok... I think I get the idea. I'm not sure I can entirely ditch arrays for queues as when the game eventually generates the musical lines, it will generate them as fixed lines that will need to be repeated in a way that a Queue seems like it wouldn't allow for, so I will still need to make an array of the notes, but I can definitely change some things around so that it's just an array of notes. It would definitely clean up the unnecessary lists of lists of lists that I have now.

    Aside, why are arrays so bad, other than the fact that they can do stuff like confuse the everloving fuck out of me?

  • RendRend Registered User regular
    Khavall wrote: »
    Ok... I think I get the idea. I'm not sure I can entirely ditch arrays for queues as when the game eventually generates the musical lines, it will generate them as fixed lines that will need to be repeated in a way that a Queue seems like it wouldn't allow for, so I will still need to make an array of the notes, but I can definitely change some things around so that it's just an array of notes. It would definitely clean up the unnecessary lists of lists of lists that I have now.

    You still don't need an array. You don't necessary want the queue if you want them to repeat, in that case you can use a linked list instead. For instance:
    public LinkedList<Notes> notes;
    public LinkedListNode<Note> currentNode;
    public RiffCallback riffCallback;
    
    ...
    
    public void noteFinished(){
      currentNode = currentNode.next;
      if(currentNode == null){
        riffCallback.riffComplete();
      }
    }
    
    
    Aside, why are arrays so bad, other than the fact that they can do stuff like confuse the everloving fuck out of me?

    Arrays are bad because you can't add methods to arrays, or fields, or anything like that. Arrays can only be architected in one way. They have only one capability, which is random access. You can't change their length/size/etc. They are incredibly limiting, and offer pretty much NO advantages whatsoever over a collection.

    Basically, they're too close to the metal. You use arrays for things like memory buffers, serialization, that sort of thing. If you need to do something complex with a set of data, you want to use a collection for it. Not doing so is basically re-inventing the wheel.

    crimsoncoyote
  • KhavallKhavall British ColumbiaRegistered User regular
    Also I'm still not sure I understand Interfaces, despite looking through the documentation many times. I guess I'm not sure when I should use interfaces and what they allow me to do.

  • RendRend Registered User regular
    edited February 2016
    Sidenote: Queues are good for when you need to go front to back and only hit everything once.

    Linked Lists are good for when you need to go front to back but don't want to throw stuff away. With a linked list it's really easy to add and remove elements (not that you necessarily need this) but more importantly for you, when using a linked list, you don't actually have to know how long the list is. You just keep going to node.next until it's null and then OH COOL I guess we're done. If you don't need to know a piece of data like the size/count of a collection, then you shouldn't try to know it. In this case you don't need to know how long a riff is, you just need to know when it's done.

    Rend on
  • KhavallKhavall British ColumbiaRegistered User regular
    ....


    I don't know how I forgot about linked lists this entire time. That's way easier.

  • RendRend Registered User regular
    Khavall wrote: »
    Also I'm still not sure I understand Interfaces, despite looking through the documentation many times. I guess I'm not sure when I should use interfaces and what they allow me to do.

    Interfaces define how objects talk to one another. Basically, implementing an interface says "this object is capable of this set of interactions"

    For instance, this interface:
    public interface RiffCallback{
      void riffFinished();
    }
    

    The RiffCallback interface is saying "this is an object that knows how to react when a riff finishes. As a riff, I am going to have an object stored that knows how to deal with it when I finish."

    Implementing RiffCallback indicates that this is a class which knows what to do in that situation. One advantage over subclassing that this gives you is that a single class can only inherit from one other class, but can implement any number of interfaces. So your RiffHandler can be a RiffCallback, and also a BonusNoteHitCallback or what have you.

    Or to say it another way: A class hierarchy heavily implies type. This IS A TYPE OF that. All the way down the tree. An interface does not imply type, it only asserts a capability.

  • KhavallKhavall British ColumbiaRegistered User regular
    I think there are lots of times where an interface would've been a great thing to use then.

    I should probably start using them.

    RendcrimsoncoyoteOatsEchoLaCabra
  • rembrandtqeinsteinrembrandtqeinstein Registered User regular
    edited February 2016
    Got an interesting Unity question that my google.fu has failed on

    I have dynamic UI text objects in my game (twitch chat bot overlay thingy) that are rendered in world space. I want to make a box collider around that text so that it interacts with other physics stuff on the screen. The text canvas the text is located in is set to 0-0 size and the text has the overflow visibility properties to true.

    Challenge: how do you measure how wide text is so I can set the size of the box collider?

    What I have tried:
    1. using the contentsizefitter then extrating the width of the parent rect transform (always 0)
    2. using the getwoldcorners method on the rect transform (always a single point)

    What I have not tried: Measuring the text itself and translating that pixel width to the proper container size (my last resort)

    edit: figured it out, you have to use the "preferred size" value of the contentsizefitter component not the "min size" value

    rembrandtqeinstein on
  • GlalGlal AiredaleRegistered User regular
    More lessons nearned with Blueprints- if your function's output pins suddenly disappear check that your exec flow inside it isn't broken someplace.
    Not only is this a counter-intuitive consequence, there are actual cases of BP functions malfunctioning due to a bug and their output pins disappearing from a couple of years back, resulting in many a red herring when trying to debug this one.

  • KhavallKhavall British ColumbiaRegistered User regular
    So before I actually commit to this, I want to make sure that I'm getting this right, because I think I'm not, and I've probably broken, just, everything.

    I've got interface noteCall, which has the void noteFinished();
    I've got class Note, which has private noteCall call. It has a public void advance(), which increases that note's tracking, checks to see if it's higher than the length of the note, and if so, calls call.noteFinished(); Note also has a pitch, length, and an int to track the number of sixteenths that have advanced while that note has been the current one in the list.
    Then I've got class NoteList:noteCall, which contains public void noteFinished() {thisNote=thisNote.next; }
    NoteList also contains some placeholder stuff(the fixed musical lines that I'm using for testing are still in an array, which it makes into the list. That part will be changed once I actually write the real generation script, which will be easier to do with using lists instead of arrays.

    Whenever a 16th note in time.deltaTime passes, the MusicManager calls thisList.thisNote.Value.advance(), where thisNote is a foreach in a List<NoteList>


    If I'm understanding the way this will work correctly, the MusicManager, every sixteenth note in time, tells the current note to advance its internal sixteenth counter. If that sixteenth counter is over the length of that note(in sixteenths, obviously), it will call the function noteFinished, on the NoteList which it was assigned on being created. That noteFinished() function will execute the code in the NoteList because of the interface magic, and will advance the list to the next note in the linked list.

    When the Towers query the MusicManager to get their pitch and delay before their next firing, they can just request a Note(int tower) that can return the specific note based on which tower is asking, and the tower can just then access the pitch and length(or probably a more efficient way to query those numbers).

    I should probably include some safety so that if you get to the end of the list it repeats instead of just finishing and getting a null forever.

    Is this right, or am I completely off-base?

  • RendRend Registered User regular
    That sounds pretty much right, but instead of having MusicManager call list.note.Value.advance(), you should probably have it call list.advance(), and then have list.advance() call note.Value.advance();
    Also, would it be possible to make the tower a NoteCallback as well? So that when a note finishes, it simply informs the tower, instead of the tower having to query the MusicManager to get that information.

  • KhavallKhavall British ColumbiaRegistered User regular
    The towers are all tied up in inheretince and subclasses and intermediary classes already from Tower base classes with their own behaviours and whatnot, so it would be a pretty big thing to make them noteCalls instead.

    I'll re-do a bit of the advance() void, that's probably cleaner.

    Thanks for the help!

  • RendRend Registered User regular
    Khavall wrote: »
    The towers are all tied up in inheretince and subclasses and intermediary classes already from Tower base classes with their own behaviours and whatnot, so it would be a pretty big thing to make them noteCalls instead.

    That's the cool thing about interfaces, it doesn't need to interrupt your inheritance hierarchy! They're interfaces!

  • MorninglordMorninglord I'm tired of being Batman, so today I'll be Owl.Registered User regular
    edited February 2016
    Okay I'm over the procrastination and now I'm back into learning unity again. I have a couple of questions.

    I have a learning disability, which is a bit of a hurdle, and unfortunately this is unfamiliar and complicated enough that I'm having trouble following the tutorials when they're unrelated to what I want to make. I want to make a 2.5 d platformer/action game, using 2d physics/colliders/etc for speed of calculation, no sprites.

    The reason to make it 2.5d is because I want ot be able to move the camera for certain things to provide small perspective changes for artistic effect, so the models have to be 3d. After looking through the manual, I think this is possible? There doesn't seem to be a sprite only restriction for the 2d controllers/colliders/2d rigidbody etc.
    The trouble is all the tutorials are basically about using sprites, which I'm not interested in. Which means I have a lot of trouble focusing and following along.
    Does anyone know any good tutorials that would be relevant, community ones or outside the unity website?
    Else I may just have to sit there and try to make one while muddling with the manual, it sounds counterproductive, but I can actually focus on what I'm trying to learn that way. It's just gonna be slower.

    Morninglord on
    (PSN: Morninglord) (Steam: Morninglord) (WiiU: Morninglord22) I like to record and toss up a lot of random gaming videos here.
  • EnigmedicEnigmedic Registered User regular
    I really have no experience with unity, but isnt 2.5d generally just 3d with the camera positioned differently?

  • MorninglordMorninglord I'm tired of being Batman, so today I'll be Owl.Registered User regular
    edited February 2016
    That's what I thought too, but you can use 3d objects in the "2d" mode. (It's an editor switch) And there are specialised physics controllers for 2d objects that are a lot faster. And I've attached a 2drigidbody to a 3d cube and it worked normally. So it seems you don't need to use sprites and still use the special 2d stuff that is meant to be used ON sprites.
    So...I think I can use the editors 2d mode and just use 3d objects. Now I need to find something that tells me what they all mean and how to use them.
    Or just look them all up one by one, if I have to.

    Morninglord on
    (PSN: Morninglord) (Steam: Morninglord) (WiiU: Morninglord22) I like to record and toss up a lot of random gaming videos here.
Sign In or Register to comment.