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
Pentecoastal Elites
Feb 27, 2007

Yeah Unity won't serialize multidimensional arrays and it sucks. I needed them in the editor, too, and this is how I got around it:
code:
[Serializable]
public class MyTable
{

	[Serializable]
	public class MyTableEntry
	{
		public int valueA;
		public string valueB;
	}

	public MyTableEntry[] boboMultidimensional;
}
It's gross but it works. There's sure to be a better way, but I haven't really broken in to editor extensions yet

Adbot
ADBOT LOVES YOU

Jewel
May 2, 2009

What's wrong with

C# code:
[Serializable]
public class Array2D<T>
{
	public int Width { get; private set; }
	public int Height { get; private set; }
	
	[SerializeThis]
	private T[] _array;

	public Array2D(int width, int height)
	{
		Width = width;
		Height = height;
		
		_array = new T[width * height];
	}
	
	public T Item[int x, int y]
	{ 
		get
		{
			return _array[x + y * width];
		}
		
		set
		{
			_array[x + y * width] = value;
		}
	}
}
Completely untested and I forget if some of these things exist or work in this way. Also consider adding resize operators and defaulting the array to something like maybe default(T) if that works, or optional param? Also watch out for struct types being copied and others being pass-by-reference, might have to tweak for that too.

Edit: Oh, completely missed needing them in the editor. It's not that hard to write a custom editor property for a type like this.

Jewel fucked around with this message at 02:11 on Oct 15, 2014

dupersaurus
Aug 1, 2012

Futurism was an art movement where dudes were all 'CARS ARE COOL AND THE PAST IS FOR CHUMPS. LET'S DRAW SOME CARS.'

Onion Knight posted:

Yeah Unity won't serialize multidimensional arrays and it sucks. I needed them in the editor, too, and this is how I got around it:
code:
[Serializable]
public class MyTable
{

	[Serializable]
	public class MyTableEntry
	{
		public int valueA;
		public string valueB;
	}

	public MyTableEntry[] boboMultidimensional;
}
It's gross but it works. There's sure to be a better way, but I haven't really broken in to editor extensions yet

In his particular case you don't even need a multi-dimension array. In a single-dimension array, the index of each cell can be calculated by something like:

code:
int GetCellIndex(int iRow, int iCol) {
     return iRow * MAP_WIDTH + iCol;
}

Vector2 GetCellCoords(int iIndex) {
     return new Vector2((int)(iIndex / MAP_WIDTH), iIndex % MAP_WIDTH);
}

(not tested, but the idea's there)

Lowen SoDium
Jun 5, 2003

Highen Fiber
Clapping Larry

BabelFish posted:

UE4 4.5 is out: https://www.unrealengine.com/blog/unreal-engine-45-released

Improvements to rendering (sub surface scattering!), UMG as a default feature, hot reload, and streaming media on UI/textures look to be the stand out features.

Streaming Media and UMG are awesome and much welcomed additions for me, but I am disappointed that HTML5 packaging didn't make it to the binary editor this version. Maybe in 4.6...

aerique
Jul 16, 2008

Lowen SoDium posted:

Streaming Media and UMG are awesome and much welcomed additions for me, but I am disappointed that HTML5 packaging didn't make it to the binary editor this version. Maybe in 4.6...

I'm pretty excited about C++ hot code reloading, although I'm not expecting the same state of bliss I get from Common Lisp development in Emacs + Slime, I'm hoping it will alleviate some issues I am having with UE4.

I'm mainly developing on OSX and my main interest is procedural generation of meshes and so far my love affair with UE4 hasn't really gotten off the ground yet. Being more a code / no-IDE kinda guy I'm having a hard time getting comfortable with UE4. The whole workflow when adding new C++ classes to a project feels clunky and I constantly feel I'm missing some fundamental knowledge to make development in UE4 go more smoothly.

Anyway, just a minor rant because I've been frustrated at my inability of getting to grasp with UE4 while it seems so easy for everyone else.

aerique fucked around with this message at 14:20 on Oct 15, 2014

JGTheSpy
Jul 31, 2002
Excuse me, but if I could have a moment of your time, I'd like to explain why you're not actually enjoying that game that you're enjoying. You see, I am in fact an expert. At games. I know, it's impressive.

aerique posted:

Anyway, just a minor rant because I've been frustrated at my inability of getting to grasp with UE4 while it seems so easy for everyone else.

I've been having the same issue. Maybe it's because I'm so used to my workflow in Unity but I've found UE4 to be utterly miserable every time I fire it up. I'm going to make my third attempt to transition this weekend but I don't have my hopes up. It doesn't help that every time I try one of their official tutorials, it doesn't compile and I lose interest before I have a chance to figure out why. I'm probably just spoiled.

evilentity
Jun 25, 2010
Are there any decent resources on entity systems? Im an idiot and im working on builder/strategy kind of game. Im using Ashley framework right now. I like it, but some extra resources would be great.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

evilentity posted:

Are there any decent resources on entity systems? Im an idiot and im working on builder/strategy kind of game. Im using Ashley framework right now. I like it, but some extra resources would be great.

http://gameprogrammingpatterns.com/component.html

That whole website is awesome actually.

Scotch Marquis
Dec 1, 2013

Onion Knight posted:

Yeah Unity won't serialize multidimensional arrays and it sucks. I needed them in the editor, too, and this is how I got around it:
code:
[Serializable]
public class MyTable
{

	[Serializable]
	public class MyTableEntry
	{
		public int valueA;
		public string valueB;
	}

	public MyTableEntry[] boboMultidimensional;
}
It's gross but it works. There's sure to be a better way, but I haven't really broken in to editor extensions yet

Not sure if there even is a better way. Formatting all of your DOM (.xml, .json) to work like arrays is my preferred way to go since Unity doesn't serialize anything more complicated than a List/Array.

Trying store your data in a more complicated fashion and having it "stitched up" at runtime is way more work than it's worth: e.g. having two arrays in a .json (one representing keys, and the other representing values) and having them assembled into a Dictionary during some initialization function when the object is instantiated.

What are you trying to deserialize that can't be represented using plain-old arrays?

Stick100
Mar 18, 2003

aerique posted:

Anyway, just a minor rant because I've been frustrated at my inability of getting to grasp with UE4 while it seems so easy for everyone else.

I haven't heard anyone say it's been easy to start coding in, but blueprint works well. I wish Unity 5 with good lighting/WebGL and the ability to use more than 3.2gb in the editor would get here already. That or the ability to use C# on UE 4.

If you watch the live stream with a European developer (can't recall the name) they show tons and tons of blueprint and he explains that they use C++ for just a few things here and there (he really wanted to get the system clock) and then expose that up to blueprint.

Stick100 fucked around with this message at 21:48 on Oct 15, 2014

evilentity
Jun 25, 2010

Yeah thats pretty good, Ive read it all some time ago. A refresh wont hurt. I would love something larger in scope though. Most of the stuff ive found are a bunch of blog posts.

Boz0r
Sep 7, 2006
The Rocketship in action.
I changed it to a single-dimensional array, and obviously, it works right away.

code:
public Tile getTile(int x, int y) {
    return tiles[y * widthTiles + x];
}
My next problem is that I have an ObjectField which loses its reference when serializing. Also, although the tile array gets saved now, it also doesn't retain its reference to the actual objects in the scene, so if I delete them in the array, they don't get deleted in the scene.

code:
grid = (Grid)EditorGUILayout.ObjectField("Grid:", grid, typeof(Grid), true);

Meridian Rizing
Sep 4, 2007

Stick100 posted:

I haven't heard anyone say it's been easy to start coding in, but blueprint works well. I wish Unity 5 with good lighting/WebGL and the ability to use more than 3.2gb in the editor would get here already. That or the ability to use C# on UE 4.

If you watch the live stream with a European developer (can't recall the name) they show tons and tons of blueprint and he explains that they use C++ for just a few things here and there (he really wanted to get the system clock) and then expose that up to blueprint.

Yeah my general approach to getting to grips with UE4 is to start with everything in blueprints and then boil it down to C++ once I get it working. The API across both seems to match up quite closely. There will also be a few thing you will keep to blueprints anyway. (Animation/Behavior Tree related)

stramit
Dec 9, 2004
Ask me about making games instead of gains.
Unity Serialization callbacks:
http://docs.unity3d.com/ScriptReference/ISerializationCallbackReceiver.OnBeforeSerialize.html

This will allow you to serialize manually things that are not supported out of the box.

Also there is this from 1.5 years ago that is a bit out of date but is mostly relevant.
https://www.youtube.com/watch?v=MmUT0ljrHNc

Polio Vax Scene
Apr 5, 2009



Boz0r posted:

My next problem is that I have an ObjectField which loses its reference when serializing. Also, although the tile array gets saved now, it also doesn't retain its reference to the actual objects in the scene, so if I delete them in the array, they don't get deleted in the scene.

This might be a problem with deep copying, where when the array is serialized, all the objects in the array are just copies of the scene objects instead of being the same object. If it is, I had the same problem when I saved my level data - what I ended up doing is replacing all the scene objects with the ones in the array when the data was loaded. You have to be careful with this though, because if your objects have links to other objects, then those also become copies, and it all just falls apart from there.

Nition
Feb 25, 2006

You really want to know?
Been messing around with Zenject in Unity for the last couple of days. It's an Inversion of Control/Dependency Injection framework. It's cool, and it has the ability to clear up a lot of Unity's inherent mess, but I was also inspired to make this diagram:



I call it "Circular Dependencies."

xgalaxy
Jan 27, 2004
i write code

Nition posted:

Been messing around with Zenject in Unity for the last couple of days. It's an Inversion of Control/Dependency Injection framework. It's cool, and it has the ability to clear up a lot of Unity's inherent mess, but I was also inspired to make this diagram:



I call it "Circular Dependencies."

Basically you've realized that all the solutions for organizing our code are really poo poo and no one has been able to come up with something that doesn't want to make you vomit.

Nition
Feb 25, 2006

You really want to know?
Yes, I thought about inserting a branching ??? entry after IoC Framework for some future construct that breaks from the circle, but decided I didn't have that much hope.

xzzy
Mar 5, 2009

I think the lesson learned is to binge code until you finish and promptly purge everything you know about the routine from your head.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

DI can have bad effects on performance, too, so that's nice.

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!
Where in that graph is the time-honored method of everything being basically globals and goto? That's got all the advantages and none of the disadvantages!

Stick100
Mar 18, 2003

roomforthetuna posted:

Where in that graph is the time-honored method of everything being basically globals and goto? That's got all the advantages and none of the disadvantages!

I actually successfully used a GOTO for the first time this in 25 years this weekend (full support for GOTO in modern C# apparently). GOTO can be a surprisingly useful method to quickly modify behavior (it was a time limited programming competition).

dupersaurus
Aug 1, 2012

Futurism was an art movement where dudes were all 'CARS ARE COOL AND THE PAST IS FOR CHUMPS. LET'S DRAW SOME CARS.'

Stick100 posted:

I actually successfully used a GOTO for the first time this in 25 years this weekend (full support for GOTO in modern C# apparently). GOTO can be a surprisingly useful method to quickly modify behavior (it was a time limited programming competition).

At the very least you've got to use C# goto for full use of switch fall-through.

code:
void SwitchThatDoesntWork() {
    switch (num) {
        case 1:
            Debug.Log("Case 1");

        case 2:
            Debug.Log("Case 2");
            break;
    }
}

void SwitchThatDoesWork() {
    switch (num) {
        case 1:
            Debug.Log("Case 1");
            goto case 2;

        case 2:
            Debug.Log("Case 2");
            break;
    }
}

Nition
Feb 25, 2006

You really want to know?
I have exactly one GOTO in the maybe ~30,000 lines of C# code in Scraps. It's in a big method where I set up a bunch of stuff, and the method can either run right through or it can finish early, but still needs to do the same clean-up code at the end either way. At the very end it assigns the results of its calculations to the object that was originally passed in.

Obviously I could call a separate "clean-up and assign" method, but it'd have to have a big list of variables passed into it that the first method created, so I made the executive decision to just "goto Cleanup" instead. Works great.

echinopsis
Apr 13, 2004

by Fluffdaddy
goto always works great


its like sticking your bumber on your car with duct tape. flawless for practicality reasons but ugly 2 look at

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Nition posted:

I have exactly one GOTO in the maybe ~30,000 lines of C# code in Scraps. It's in a big method where I set up a bunch of stuff, and the method can either run right through or it can finish early, but still needs to do the same clean-up code at the end either way. At the very end it assigns the results of its calculations to the object that was originally passed in.

Obviously I could call a separate "clean-up and assign" method, but it'd have to have a big list of variables passed into it that the first method created, so I made the executive decision to just "goto Cleanup" instead. Works great.

I found some old code of mine that exits a loop early (almost as bad as goto!) that's similar to what you describe; I'm passing in like a dozen extrapolated values and just don't want to have to deal with them after a certain point. In the one case where further processing isn't necessary this was the comment:
code:
'Overwrite everything and get the gently caress out

Nition
Feb 25, 2006

You really want to know?
Should've used goto GetTheFuckOut.

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

echinopsis posted:

goto always works great


its like sticking your bumber on your car with duct tape. flawless for practicality reasons but ugly 2 look at

I like the analogy. Both sound reasonable at the time and both can lead to disaster if it comes into contact with someone else.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Nition posted:

the method can either run right through or it can finish early, but still needs to do the same clean-up code at the end either way

try-finally?

echinopsis
Apr 13, 2004

by Fluffdaddy
Everyone is trying to get my man nition to weasel out of the GOTO


I like to think every software worth a drat has a GOTO hidden in there somewhere. Like taking a jizz in the coleslaw at KFC, you just know that ONE of those pottles has it. It's like a signature.. "I was here" it says "I was alive. I EXISTED"

Polio Vax Scene
Apr 5, 2009



Well that certainly was a post.

Nition
Feb 25, 2006

You really want to know?
There's only the one goto, I promise.

echinopsis
Apr 13, 2004

by Fluffdaddy
Yeah and only "one" pottle of coleslaw at KFC has the special sauce


I got your back don't you worry ;)

Jo
Jan 24, 2005

:allears:
Soiled Meat

JGTheSpy posted:

I've been having the same issue. Maybe it's because I'm so used to my workflow in Unity but I've found UE4 to be utterly miserable every time I fire it up. I'm going to make my third attempt to transition this weekend but I don't have my hopes up. It doesn't help that every time I try one of their official tutorials, it doesn't compile and I lose interest before I have a chance to figure out why. I'm probably just spoiled.

Pardon me for adding to the circlejerk. I'm in complete agreement. The damndest thing is I can't seem to figure out exactly WHY Unity is easier to work in than Unreal. I would chalk it up to experience, but I really am not all that familiar with Unity. I'd chalk it up to the availability of online examples, but I rarely find myself going to those for most of my problems. I thought at first it was autocompletion, but Visual Studio should blow Monodevelop out of the water. Anyone's guess is as good as mine. Does component based vs. class based really contribute that much? Does C++ really provide that much more headache than C#. We already had the 'boilerplate' discussion, but I've not had any additional insights since then.

I'm still hopeful for Unreal4. It's pretty and the level editor actually works exceptionally well.

Unormal
Nov 16, 2004

Mod sass? This evening?! But the cakes aren't ready! THE CAKES!
Fun Shoe

Jo posted:

Pardon me for adding to the circlejerk. I'm in complete agreement. The damndest thing is I can't seem to figure out exactly WHY Unity is easier to work in than Unreal. I would chalk it up to experience, but I really am not all that familiar with Unity. I'd chalk it up to the availability of online examples, but I rarely find myself going to those for most of my problems. I thought at first it was autocompletion, but Visual Studio should blow Monodevelop out of the water. Anyone's guess is as good as mine. Does component based vs. class based really contribute that much? Does C++ really provide that much more headache than C#. We already had the 'boilerplate' discussion, but I've not had any additional insights since then.

I'm still hopeful for Unreal4. It's pretty and the level editor actually works exceptionally well.

Component-based-engine superiority. :yarr:

Centripetal Horse
Nov 22, 2009

Fuck money, get GBS

This could have bought you a half a tank of gas, lmfao -
Love, gromdul
I just want to say that no fall-through in switch statements is bullshit.

Carry on.

Jewel
May 2, 2009

Unity is "easier" because you just create a component, drop it on any object, and it works. That component can be a HealthComponent that displays a healthbar and keeps track of health, also providing a small API to damage or whatever. The problem with Unity is that this is only useful to the smallest of indie games, when you're just starting out and don't know any better about proper code formatting. What happens when you want to add armor? Do you just lump it with the HealthComponent? What happens if you calculate the player's facing direction in a PlayerMovement component, and you want the direction in another script? You have to couple it with PlayerMovement just to get the direction, and by the end of a complex player, everything's coupled so tightly that you might as well just have one huge megacomponent, and by that point you'll probably just be wishing you could have coded the entity to begin with, rather than using components.

The other problem with unity is how there's just so many missing tiny features all over the place. You want to zoom out on the animation preview? Sorry! You want to adjust the handle lengths on an animation curve? Sorry! You want to undo while editing an animation curve? Sorry! Not to mention crashing around every corner.

And then you get into stuff like unity not even providing a way to make savegames without external plugins written by people who don't really know how to provide an intuitive interface. Or the GUI system being horrible and requiring you pay $100 for a better system (potentially fixed in newer versions but I wouldn't hold my breath). Or having no decal system whatsoever (and a huge flaw that I recently discovered is that in DirectX11 in deferred rendering mode there seems to be no way to have shadows on a transparent (alpha blended) surface, so any custom decals won't work because they'll be fullbright in shadows.

The only advantage Unity has is C# is easier, and it was more accessible, but now Unreal is opening up (in both source code and ease of availability) and hopefully Unity will be wiped from existence in a few years.

Edit: Also it's more than possible to make some pretty complex games with blueprints alone; no code at all, so that's a possibility if you really hate C++ that much; or can't code.

Jewel fucked around with this message at 23:54 on Oct 21, 2014

Calipark
Feb 1, 2008

That's cool.
As someone who recently was forced to make the switch from Unity to UE4, I can relate to feeling a bit lost.

But trust me, once it clicks and you get comfortable with the C++/Blueprint structure you'll never look back.

Jewel posted:

Also it's more than possible to make some pretty complex games with blueprints alone; no code at all, so that's a possibility if you really hate C++ that much; or can't code.

People who make games entirely in Blueprint are in for some pain. While it's totally possible to make small games entirely in Blueprint, the entire system is built to be extended and manipulated in C++.

Currently, my method is to make C++ classes that get extended into Blueprints in my project to handle hooking up assets and do minor adjustments / hook into UMG.

It also makes for an excellent place to prototype and poke at the various APIs, but I always refractor any complex expensive stuff back into the C++ class.

The engine handles that very smoothly, the Blueprint sub-classes are updated with the new functionality as soon as you compile without any hassle.

Calipark fucked around with this message at 00:24 on Oct 22, 2014

echinopsis
Apr 13, 2004

by Fluffdaddy
I'd never done development before starting UE4 so I have started fresh with blueprints. The problem with UE4 as such is that there are many ways to do a thing, but it's never really clear if you've done it the best way. And a lot of the examples show you how to achieve something but not necessarily in the best way. For example, the ball rolling demo works fine, and the player camera is attached to the rolling ball BluePrint. This works and I used that idea with my game for a bit, but it turns out, that while it's a quick and easy way to do it, it's not the best way at all. If you use a Camera Manager, and make it point at whatever you're controlling, you have a lot more flexibility. That's just an example but my entire journey for 3 months has been through doing something with no clear direction and only later realising I did it a poor way. Perhaps this issue is on all engines, but it just doesn't help the the examples don't help, and that the tutorials don't tend to cover anything past getting started. I can definitely see people getting lost and I've had to spend a lot of time learning a lot of things through trial and error and reading forum posts etc just how to do things.

Welp

Adbot
ADBOT LOVES YOU

Calipark
Feb 1, 2008

That's cool.

Welcome to GameDev.

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