# Unity Scene design.

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

## Recommended Posts

Hello everyone,

I currently need to decide what type of scene will my game need.

a/ A root and only one level of children.

b/ Not only the root but all objects can have children

What is making my decision harder is that I don't know what the physics engine will do.(I guess bullet physics)

If I didn't have physics -> I've got bus and a character. Bus is parent of character -> character's matrix is being multiplied by its parent to find where I should draw it.(and where should the logic process it)

I don't know how physics handle these stuff. I don't know can there be any connections like this(I've been playing with unity3d. I know just the most basic stuff about physic's objects)

For the design itself I'm following ( http://software.intel.com/sites/default/files/m/d/4/1/d/8/Designing_a_Parallel_Game_Engine.pdf )

I have an universal scene. I create the bus and character there like I said above. How should I recreate this in the physics system's scene?

Should it be flat? Do I need some connection between a parent and a child(like the transform multiplication like I said above)?

Note: I don't need really advanced physics simulations, just rigid body and collision.

So...how would you do this?

##### Share on other sites

In my opinion it would be best to have all scene objects capable of being a parent and to hold children. It will just make object handling a little easier. Something like the following maybe?

class SceneNode
{
std::list<SceneNode*> children;

nodes and any other common node methods too*/
};

class Bus : public SceneNode
{
/*Bus related methods*/
};

class Character : public SceneNode
{
/*Character related methods*/
};


As for physics, you mentioned Bullet...It holds it's own scene structure and feeds your scene objects with updated transforms. So it basically runs independently to your scene graph and you'd be using Bullets interface to move objects around. To create rigid bodies you feed Bullet with raw geometry (or use simple primitives) and positional data. You'd then tell Bullet what rigid bodies are attached to each other (parent/child relationships).

Note: I don't need really advanced physics simulations, just rigid body and collision.

Unfortunately once you start colliding multiple objects together and want correct collision detection and response, it becomes rather tricky, and implementing your own solution basically ends in recreating the wheel so to speak. Bullet will only do what it needs to do in terms of calculations so you wont be loosing out by using it.

Edited by Nyssa

##### Share on other sites

Thank you for the answer. Pretty much everything I need. I already have experience coding such things(however without physics) and I usually do the same thing you suggested.

I'll just make my universal scene which support parent/children, create a function which will iterate through parents to get the real world position of the node. Then I'll create the physics system like a wrapper to bullet physics. Bullet will take care of its own structures.

##### Share on other sites
Don't think of it as a monolithic structure. Keep as many copies of the data as you need. Graphics system needs to cull geometry based on visibility? Keep a quadtree/bsp tree/whatever around. Need to quickly look up certain game objects based on string keys? Keep those in a dictionary. Need a data structure specialized for physics? Have one of those around (if you're going to be using a 3rd party physics api then it will keep it's own copies of the data it cares about).

A general purpose scene probably doesn't need to support parent-child relationships. You only really need that for calculating world transforms (and you've got another class for that right?). If this is the "master list of all game objects" type of scene, then really all it needs to be is an array or some sort of dictionary if you have unique ids. Edited by turch

##### Share on other sites
my strategy:

the large scale world is divided up into "regions". each region is a fixed sized space (basically like a big cube), and they are laid out in a giant grid. as-is, the regions are 512x512 meters (or 16384 ~1.25 inch "units").

an idea here is that a player may only see into at-most the 4 nearest regions, and anything beyond this can be saved to disk and unloaded (or reloaded again if it comes back into the visible list).

within each region (apart from voxels), objects are sorted according to a dynamically build BSP-like structure.
this tree is rebuilt as objects are added/destroyed or move around.
the advantage of a tree like this is that it allows quickly answering questions like "what is the nearest X" or "is there anything in this particular area of space?", without needing to check against every object in the scene.

say, an object is running or falling, do we really want to check against every object in the scene every tick? typically not.
a tree allows quickly identifying and eliminating the vast majority of objects for which there is no chance of colliding with them.

however, this tree is not directly regarded as part of the object (in the same sense as parent/child relationships), but is more sort of a "behind the scenes" type thing, and as an object moves around, the tree might change around under it, or if it crosses a region boundary might actually jump from one BSP to another.

most entities and similar are otherwise treated as more-or-less a flat list. typically, there are not any explicit parent/child relationships, but some relationships may exist informally (for example, projectiles remember who fired them, AIs/NPCs remember who their current enemies are, ...).

during run-time, each entity may also be assigned an "ID number" used to identify it (like, over the network protocol), but this ID number is not persistent.

note though that there is not actually a single unified list of objects for the entire engine, but rather there may be around 4 of them:
the server-side scene-graph, which basically tracks all world objects (and runs all the AI, physics, ...);
the physics-engine graph, which mostly just deals with objects using fancy physics (otherwise, the physics engine is idle);
the client-side scene-graph, which basically contains whatever entities the server is telling the client about (the locally visible collection of entities, which basically holds information like each objects location/velocity/model/frame/effects/...);
the renderer's "modelstate" list, which mostly keeps track of currently-visible scene objects (this may include things like the instance of an entity's skeletal model, its current bone positions, per-frame vertex/normal and triangle-face arrays, ...).

so, for example, if an entity exists on the client, it may be given a modelstate if it is potentially visible, but may not get a full state until it is determined "actually visible" by the renderer (is uses a special visibility-determination pass, employing various checks to try to determine what is/is-not relevant to the current visible scene), and an entity wandering off-camera may well have its modelstate destroyed (the modelstate graph is thus highly volatile, and in some cases the renderer may destroy it at-will, forcing the client-end logic to rebuild it).

the reason for different lists is that they exist in different parts of the engine and deal with different information.
for example, the server-side entities contain lots of fields that have no relevance to the renderer;
and, the renderer contains lots of fields that have no relevance to AIs or physics;
and, for example, the client-side scene-graph knows a model by its model-name, and largely manages communication with the server, whereas the renderer's modelstate knows it via an instance pointer and internal (model-type specific) vtables (and non-visible objects are never given a modelstate);
...

well, and also because my engine is mostly broken up into multiple DLLs, and I prefer not to share structures between different libraries.

or such... Edited by cr88192

##### Share on other sites

What is making my decision harder is that I don't know what the physics engine will do.(I guess bullet physics)

I'm not sure what it's causing you trouble here. Physics representation must totally be separate from others.

It is worth noticing that for anything that is not a dynamic object (Bullet slang) the physics does absolutely nothing, in the sense the objects will stay still by themselves.

Kinematic objects do move according to application, not physics.

You'd then tell Bullet what rigid bodies are attached to each other (parent/child relationships).

Actually no, they are not parent/child relationships. There's no such thing as a "parent" rigidbody. Connecting rigidbodies by a constraint gives them equal rights.

I actually read a lot of possibly premature optimizations in this thread. Last poster even takes a stab at streaming, client-server architectures and such. My personal suggestion is to use iterative design. Add features after you have the need for them. You cannot design a solution for a need you don't understand.

Actually, my "scene" is a std::vector of batches. Yes, you read it right. I don't even need to make it hierarchical. Yes, I do have problems with my most complex data sets on the lowest end hardware I'm targeting (which is 1st gen Intel Atom FYI). Realistic datasets run just fine.

##### Share on other sites
actually, I was mostly describing how my engine works, as an example...

granted, it does itself use a client/server architecture (both in single and multiplayer), and loads/saves parts of the world dynamically.

actually, in this whole design, the server end is the main authority (pretty much everything on the client-end is streamed over from the server).

• 10
• 9
• 12
• 10
• 12
• ### Similar Content

• Hey guys,
I have a really weird problem. I'm trying to get some data from a REST service. I'm using the following code:

private void GetTheScores() { UnityWebRequest GetCommand = UnityWebRequest.Get(url); UnityWebRequestAsyncOperation operation = GetCommand.SendWebRequest(); if (!operation.webRequest.isNetworkError) { ResultsContainer rez = JsonUtility.FromJson<ResultsContainer>(operation.webRequest.downloadHandler.text); Debug.Log("Text: " + operation.webRequest.downloadHandler.text); } } The problem is that when I'm in Unity's editor, the request doesn't return anything (operation.webRequest.downloadHandler.text is empty, the Debug.Log command just prints "Text: "), but when I enter the debug mode and insert a breakpoint on that line, then it returns the text properly. Does anyone have an idea why is this happening?
The real problem I'm trying to solve is that when I receive the text, I can't get the data from the JSON. The markup is really simple:
[{"id":1,"name":"Player1"},{"id":2,"name":"Player2"}] and I have an object that should accept that data:
[System.Serializable] public class ResultScript { public int id; public string name; } There is also a class that should accept the array of these objects (which the JSON is returning):
[System.Serializable] public class ResultsContainer { public ResultScript[] results; } But when I run the code (in the debug mode, to get any result) I get an error: ArgumentException: JSON must represent an object type. I've googled it but none of the proposed solutions work for me.
Also (regardless if I'm in the debug mode or not) when I try to do some string operations like removing or adding characters to the GET result, the functions return an empty string as a result
Can you help me with any of these problems?
Thank you
• By nihitori
The Emotional Music Vol. I pack focuses on beautiful and esoteric orchestral music, capable of creating truly emotive and intimate moods. It features detailed chamber strings, cello and piano as the main instruments, resulting in a subtle and elegant sound never before heard in video game royalty-free music assets.

The pack includes 5 original tracks, as well as a total of 47 loops based on these tracks (long loops for simple use and short loops for custom / complex music layering).

A 15 seconds preview of each main track is available on Soundcloud:

• Another one of our new UI for #screenshotsaturday. This is the inventory screen for showing what animal fossils you have collected so far. #gamedev #indiedev #sama

• We're looking for programmers for our project.
Our project is being made in Unity
Requirements:
-Skills in Unity
-C#
-Javascript
-Node.js
We're looking for programmers who can perform a variety of functions on our project.
Project is a top-down hack-and-slash pvp dungeon-crawler like game. Game is entirely multiplayer based, using randomized dungeons, and a unique combat system with emphasis on gameplay.
We have a GDD to work off of, and a Lead Programmer you would work under.
Assignments may include:
-Creating new scripts of varying degrees specific to the project (mostly server-side, but sometimes client-side)
-Assembling already created monsters/characters with existing or non-existing code.
-Creating VFX
This project is unpaid, but with royalties.

---
Summary:
Bassetune Reapers is a Player-verus-Player, competitive dungeon crawler. This basically takes on aspects of dungeon crawling, but with a more aggressive setting. Players will have the option to play as the "dungeon-crawlers" (called the 'Knights', or "Knight Class", in-game) or as the "dungeon" itself (literally called the 'Bosses', or "Boss Class", in-game). What this means is that players can choose to play as the people invading the dungeon, or as the dungeon-holders themselves.
Key Features:
-Intense, fast-paced combat
-Multiple skills, weapons, and ways to play the game
-Tons of different Bosses, Minibosses, creatures and traps to utilize throughout the dungeon
-Multiple unique environments
-Interesting, detailed lore behind both the game and world
-Intricate RPG system
-Lots of customization for both classes s of customization for both classes

• Custom coffee mugs have arrived... More caffeine!
Have a great weekend everyone!
#gamedev #indiedev #sama #caffeine