• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ferrous

Oh Unity, what a strange decision you have made.

12 posts in this topic

Its probably a bit of a misstep to allow implicit conversion like that, but I don't know that its terribly egregious either. Particularly in the other direction its common and convenient to convert implicitly, and its possible they viewed consistency of requiring the explicit conversion as more important than preventing this particular pothole -- although I would personally disagree with that since round-tripping down and back again effectively zero's the trailing dimensions. I would probably be tempted to make upwards conversions implicit, but downwards conversions explicit.

1

Share this post


Link to post
Share on other sites

It's certainly not the worst Coding Horror I've ever seen, but it's definitely the first Vector math class/structs that I've seen that allow implicit conversion both ways.  It just doesn't seem like much of an advantage is gained over simple type safety.  

0

Share this post


Link to post
Share on other sites

Ehh, I'm on a fence on this.

 

On one side its very convenient, but explicit conversions are kinda annoying to write.

 

Now, if you could do it in a GLSL-like way, ie:

 

vec2 interpValue = vec2(lerp(val0,val1,delta).xy);

 

That would be both convenient and explicit enough for me.

2

Share this post


Link to post
Share on other sites
I only use implicit conversion operators if I'm the only person who will EVER use the type. Otherwise it's explicit operators or ToX() methods.

Unity could have easily used 'explicit' instead of 'implicit' when defining those operators. Edited by Nypyren
0

Share this post


Link to post
Share on other sites

It kinda depends on legacy of the code -- explicit conversion constructors have been around since C++98, but explicit conversion operators are new in C++11. Depending on how they chose to implement them, and their other considerations in doing so, explicit conversions might not have been an option at the time (outside of named conversion functions, like ToX member functions).

 

Its also one of those things where changing it after the fact would yield a more-restrictive API surface than before. You can make things less-restrictive over time without breaking source compatibility, but you can't be more-restrictive without breaking source all over the place. Yes, it's better to be explicit, but try telling that to the 100s of millions of lines of unity code that exists, and those who have to maintain it.

0

Share this post


Link to post
Share on other sites

It kinda depends on legacy of the code -- explicit conversion constructors have been around since C++98, but explicit conversion operators are new in C++11

Unity uses an old version of C#/Mono wink.png

 

At the least, the code should probably look something like:

Vector2 interpValue = Vector3.Lerp(value0, value1, deltaTime).ToVec2();

or

Vector2 interpValue = Vector3.Lerp(value0.ToVec2(), value1.ToVec2(), deltaTime);

or

Vector2 interpValue = Vector2.Lerp(value0, value1, deltaTime); //overload that takes vec3 arguments

Edited by Hodgman
1

Share this post


Link to post
Share on other sites
IIRC it was a change they introduced mid 2013, along with other preparatory changes for the eventual Unity 2D environment.

I'm not seeing it specifically in the change logs, but there is a definite cutoff point where in the unity3d forums people stopped complaining about the difficulty of converting the Vector2 mouse coordinates into vector3 objects.
0

Share this post


Link to post
Share on other sites
As nice as it may be it introduces bugs that are horrible to track down as well, for example dropping a script containing this on a 2D-only object (e.g. a sprite) does not produce an error but crashes the editor instantly:

void Update() {    rigidbody.AddForce(Vector3.up * 10);}
Took me while to figure out that the reason for the editor to crash as soon as I hit play was that I wrote "rigidbody" instead of "rigidbody2d"...

Edit: Not even a simple warning is emitted.
0

Share this post


Link to post
Share on other sites

As nice as it may be it introduces bugs that are horrible to track down as well, for example dropping a script containing this on a 2D-only object (e.g. a sprite) does not produce an error but crashes the editor instantly:
 

void Update() {    rigidbody.AddForce(Vector3.up * 10);}
Took me while to figure out that the reason for the editor to crash as soon as I hit play was that I wrote "rigidbody" instead of "rigidbody2d"...

 

 

And even then it cringe, as it should be:

void Update() {    rigidbody2D.AddForce(Vector2.up * 10);}

Though you can get away with it anyway, since the up vector just happens to be 0,1,0, it still irks.

0

Share this post


Link to post
Share on other sites

IIRC it was a change they introduced mid 2013, along with other preparatory changes for the eventual Unity 2D environment.

I'm not seeing it specifically in the change logs, but there is a definite cutoff point where in the unity3d forums people stopped complaining about the difficulty of converting the Vector2 mouse coordinates into vector3 objects.

 

Waaa?  Is it really that hard to do mouse3 = new Vector3(mouse.x,0.0, mouse.y) or however you want to divvy up the values?

 

 Also, I am in complete agreement with Hodgman, I really wouldn't have minded if they had a .ToVector2() or .ToVector3() function, but doing it behind my back is what drives me crazy.

0

Share this post


Link to post
Share on other sites

This happens all of the time in shader code, and I firmly believe it to be Evil. It has been the source of many bugs that were difficult to track down. Fortunately the HLSL compiler will emit a warning when it truncates vector types, so if you enable treating warnings as errors then you can catch it.

 

Yeah, I'm a firm believer in catching as many errors as possible at compile time, which is why I like languages that are strongly typed. 

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0