• 11
• 9
• 10
• 9
• 11
• ### Similar Content

• Hello forum,
I have some decent amount of experience in Unity making games for Software Engineering projects in college, these were very specific projects however and I still am fairly new to building games. I wanted to make a game that uses the shadows of objects for collision detecting (i.e. shooting a gun at a characters shadow causes that character damage. What is the best engine to do this in (game will be 3D), and does anyone have any advice on how to approach this concept? I consider myself fairly experienced in programming, but game dev is just an entirely different beast.
• By juicyz
Hey all,
I've been slowly working on my game called AotW for a while now.  I have come to the conclusions that it would be nice to cooperate with 1 or 2 others to help finish it.  Ive been trying to keep my GDD up to date with my ideas and development so that would give a better overview of the game when the time comes.  Currently I have a basic skeleton of the RPG elements needed but everything can still be discussed and talked about and we can transform my idea to something the group likes.
The premise of the game is a Diablo-like procedurally generated map with RPG elements that include sockets, inventory, classes, abilities, crafting, loot, items, sockets, and enchanting.  This will be done in a 2D iso view as I can't do 3D art and I enjoy 2D games a lot.

I don't plan on releasing this as this is more of a hobby project for me and I have a full-time job.  Though I'd like to start putting more hours into development and having others definitely will be motivation.  I also want to be able to say I have finally "finished" a game idea to some degree.  If the time comes and we want to release it, then we can go ahead and do so but that's not my purpose or plan.

Discord:
Juicyz#3683

Thanks,
Juicyz

• Hi, I've been working on this issue for a while and haven't yet found an answer.
Does anyone know the best way to convert unity's LAT & LONG into a vector 3 position that I could use in a virtual world (if it's even possible).

• I am taking an absolute beginner's game development course and we have just finished game jams in small groups. Our current assignment is to get feedback from people working in any aspect of game development. I would very much appreciate any feedback! The game is up on itchi.io (sound warning) https://wobbegong.itch.io/zombie-shooter It's essentially a very basic PvE.
I also have some things I'm wondering about, but you don't necessarily have to answer these.
1. Do you have any tips on working with physics? My group wrestled a bit with Rigidbody physics not totally working the way we wanted to -- jumping ended up kind of floaty and inclines seem to mess up movement. Alternatively... how can I build terrains with depth that won't result in wonky physics?
2. How can I keep up the level of challenge in an interesting way as the player progresses through the waves?
3. What are some of your personal guidelines for creating title screens?
Thank you very much in advance!

• I'm having a weird issue with detecting a collision. I've tried everything I could find online but nothing seems to work. I have a brick object. It has a 2D Collider attached and I have also attached a 2D Rigidbody on it. I also have an EndScreen 2D Collider. The EndScreen 2D collider is tagged with "EndScreen". I am trying to detect when a brick collides with the end screen collider and simply print "game over" in the console.
This is my current code for this part of the program, it is attached to the bricks:
void OnCollisionEnter (Collision2D collision) { if (collision.gameObject.tag == "EndScreen") { Debug.Log("Game over"); } } Several things have happened depending on the set up. If I have the rigidbody 2D set as static, my ball object can still collide with the bricks, but I get no Log message. If I set it to Kinematic or Dynamic, I get absolutely no interaction between the ball and the bricks, and nothing when the bricks pass through the collider. I have tried to set the collider to a trigger and use OnTriggerEnter2D, no change. I have tried to put the rigidbody on the EndScreen object and tried to set it's body type to all 3 settings, no change. The only thing I can think of that I have not done is put the script on the EndScreen object and switch the tag to the bricks. The reason I have not done this is because I will have several types of bricks, some of which will have different tags.

Please tell me somebody can see what I'm doing wrong here, because I'm losing my mind over something I feel should be ridiculously simple. Thanks.

# Unity Question regarding indexes to entities and scripts

This topic is 4033 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Quote:
Original post by ApochPiQ
Quote:
 Original post by Nitage In fact, I find reusing Ids a bit nasty - what happens if (say in an rts) a unit diedhalf an hour ago, but a script kept around a reference to it? Do you want to be able to tell the script that the unit in question no longer exists? Or would you prefer to hand it a reference to a totally different unit?
If this scenario ever occurs, you have serious design issues anyways, and likely some major bugs lurking under the surface. When the unit dies and becomes non-existent, every reference to it should be released. Your systems should be built in a way that makes it trivial to track all known references to a given resource or entity; as a logical consequence, it should be trivial to remove those references if an entity stops existing. If this is not a very simple process, chances are the design has some major weaknesses - most likely excessive coupling, probably some temporal coupling, and certainly a lot of unwritten and unverifiable assumptions.
This scares me because it's basically saying "Your program is going to have bugs, Ezbez!" I have a system similar to what was discussed in the linked thread. I have integer IDs for everything, and I create a new one by adding one to the last one that was made. No duplicates, no worries, eh? But now ApochPIQ tells me that it's fundamentally wrong and the very fabric of game-time is going to collapse on me one of these days because of it. Can anyone help me with this? I want a nice system, but I'm not sure how I can improve upon my current system. I guess some more details about my current system might be useful. I internally store Entities and expose them via EntityHandles to scripts. The EntityHandles don't actually ever give out an Entity, they wrap all function calls to the Entity between another layer. This layer checks that the Entity is still valid, if not, it does nothing and returns some generic nothingness to do no damage. Scripts only ever touch EntityHandles, and can store them. EntityHandles internally store indexes to the Entities.

##### Share on other sites
When your entity dies, all references in the scripts should die too, so they should never have to manage a NULL handle. Else, you scripts might for example, leak memory quite badly (for example, accessing the entity one hour after its deletion. That's not really a good idea).

It is not recommended to silently discard NULL handle. At the very least, assert. It's like a memory violation, like accessing a dangling pointer. The exception is that you can obviously carry on the execution, during the development time. But in final builds, these should be ironed out.

If you are not confident with re-using Ids, that's fine (as long as you use a fast lookup / hash table), but consider accessing NULL handles to be a bad thing at least.

##### Share on other sites
I use references to pass around.

Since the code requires either serialized references or local objects, I use a single reference that stores the serialized id and smart pointer.

Then I overload the -> and * operators to make handling transparent.

Something like this:
template < class T >class ObjectRef {public:  ObjectRef( ObjectPtr ptr )    : m_ptr(ptr)    , m_guid(ptr->guid())  {}  ObjectRef( ObjectGUID guid )    : m_ptr(NULL)    , m_guid(guid)  {}  T operator ->() {  {    if (!resolve() ) throw ...    return m_ptr;  }private:  bool resolve()  {    if ( m_ptr.is_null() ) {      // do lookup to obtain instance      if ( ... not found ... )        return false;      else        m_ptr = ....    }     return true;  }  ObjectGUID m_guid;  ObjectPtr m_ptr;}

The scripts are passed the ObjectRefs.

void invoke_action( EntityRef &ref ){  ... script( ref )}

Here, I don't fuss much if object gets "destroyed" while script is holding a reference to it. Smart pointers make sure the object is still around, it's just disconnected from the event system.

And since all scriptable actions can only hold references for duration of function call, this overlap is minimal.

This isn't optimal, and I use it in networked game, so my requirements might be somewhat different, but they do the task.

When an object is destroyed, it's simply removed from global directory. Smart pointers take care of the rest.

In addition, it allows me to defer resolution of serialized references until they are needed - some might never need to be resolved.

##### Share on other sites
This reminds me of a minor bug in Warcraft 2. Summoned skeletons have a timed lifespan, after which they automatically die. A player can load a skeleton onto a transport ship and then wait for it to die. The slot on the transport will then appear empty. The next unit created will appear inside of the transport instead of where it was supposed to. Even units that shouldn't be allowed on the transport, like flying units, other ships, enemy units, and buildings. The bug wasn't that serious because summoned skeletons were fairly worthless and have a long lifespan, so it didn't happen in real games.

Just an example that shows this sort of bug has actually occured in commercial games.

##### Share on other sites
But how can I fix it? I'd like to be able to keep references in scripts for longer than the duration of one script. And I'm not sure how I'm supposed to go about handling the removal of all references. I could do that, but I'm not sure how that will work for scripts. For example, if Entity A gets a reference to B, then B dies. What should A do if it's handle to B disappears? Suddenly it'll be accessing a non-existant variable - the very thing I was trying to avoid when I created EntityHandles.

Edit: Though I don't really see how it takes care of the problem at hand, I really must say that I like your system Antheus. It seems like just the thing I was looking for to avoid having to do a lookup in an std::map every single function call.

##### Share on other sites
Essentially you have a requirement, which is to ensure that your references stay safe to use. Either that can be by magically removing all references to something unsafe, or it can be by making references to dead things just as safe as references to living things. The first way requires that each entity knows who refers to it (eg. observer pattern, smart pointers), but gives you the benefit of knowing that you never have null references.

Either way requires that you have a system in place for handling what happens to a script with a null reference. If your language uses exceptions, defining a standard exception for this purpose makes sense. If not, you have various choices - the 'generic nothingness' of the original post is one option, though perhaps not the easiest to debug when scripts misbehave.

In other words, I think ApochPiQ is perhaps overstating the problems. It's safe to keep dangling references if your references are safe to use, and if you don't recycle ids. If either of those are false, you need to get rid of references as soon as they become invalid. That's all.