Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: ElProfessor595 on May 25, 2019, 06:34:43 AM

Title: How to instantiate a Game Object ?
Post by: ElProfessor595 on May 25, 2019, 06:34:43 AM
Hi everyone, I job on a minecraft clone project. I use prefabs of a cube with multiple empty gameobjects, only with triggers. I use a raycast system for create clones. But after many, many, many gameobjects, the game was very slow. I know if I create too many object, the game will slow. I want instantiate these cubes, for use less resources. Someone know how to do it, without code ?

Thanks for all yours answers.
Title: Re: How to instantiate a Game Object ?
Post by: Fat Pug Studio on May 25, 2019, 10:05:46 AM
Use pooling for cubes. The thing with minecraft-like games that use many cubes is that they don't ACTUALLY ise that many, they merely activate and deactivate the visible and invisible ones. You basically have a 3d grid with coordinates, every coordinate is holding data about the cube type, and whether is it visible or not, and spawns cube when it's visible.

Hope that helps, you just need to figure out the way of storing and retrieving the grid data in the most efficient manner.

Title: Re: How to instantiate a Game Object ?
Post by: ElProfessor595 on May 25, 2019, 01:12:20 PM
Thanks krmko for your answer, but the generation of the cubes isn't a problem for me, I just want to know if I can instantiate a gameobject.

But thanks for your answer, maybe I'll use it later.
Title: Re: How to instantiate a Game Object ?
Post by: Fat Pug Studio on May 25, 2019, 01:35:01 PM
Well i though you were having problems because you're using instantiation instead of spawning.

Use create object action for instantiation if you wamt to instantiate them.
Title: Re: How to instantiate a Game Object ?
Post by: ElProfessor595 on May 26, 2019, 09:15:31 AM
But there isn't create a instance action. I think I'll give you screenshots.
The first picture represent the cube. There are 6 gameobjects in the cube, every object have a trigger. The generation script isn't with the cubes, but with the camera. As I have said, the generation isn't a problem for me. I saw the "Create Object" action, and I haven't seen the type of game object (like a clone or an instance). Do you know how I can create instances ?
Title: Re: How to instantiate a Game Object ?
Post by: Fat Pug Studio on May 26, 2019, 09:56:12 AM
Sorry, i don't understand what you're aiming at, game object in the scene = instance. If you want to create more instances, you need to put game object in the scene that will have fsm that will create new instances from prefabs.

I recommend some starter unity and playmaker tutorials to learn basics before moving forward.
Title: Re: How to instantiate a Game Object ?
Post by: ElProfessor595 on May 26, 2019, 10:30:11 AM
Are you sure any gameobject in the scene is an instance ?
Title: Re: How to instantiate a Game Object ?
Post by: djaydino on May 26, 2019, 07:35:30 PM
Hi.
When you use a Create object, you are creating a instance of the selected object (prefab, scene object)
Title: Re: How to instantiate a Game Object ?
Post by: daniellogin on May 26, 2019, 11:55:23 PM
Are you sure any gameobject in the scene is an instance ?
Maybe you need to say why you want an "instance", so just describe what you want to achieve or avoid or etc.

Eg; what is wrong with creating a prefab of the object, then just doing a 'create object' when ever you need one placed in the scene? What does this "thingamabob" need to achieve, or what special requirements does it need to meet?
Title: Re: How to instantiate a Game Object ?
Post by: djaydino on May 27, 2019, 07:59:24 AM
Hi.
I think the is a misunderstanding on what instance means.

Quote
"Instance" is a general language concept, not strictly limited to programming, and refers to one specific occurrence of a thing, idea, or situation.

In programming, an instance is usually created as a copy of some template, which can that have it's properties modified to make it distinct and unique from other instances.

if you open the 'Create Object' Action script, inside the script you can see that the object is instantiated :

Quote
95    var newObject = (GameObject)Object.Instantiate(go, spawnPosition, Quaternion.Euler(spawnRotation));

Now the main problem "ElProfessor595" has is that after placing a whole bunch of objects, the game gets slow.

In Minecraft for that reason the world is loaded in chunks.
a chunk is  256 block tall and 16 × 16 wide.
These chunks get loaded/unloaded by distance from player. (closer ones get loaded, further ones unloaded)

The chunks can be stored in xml/arrays so that when you load a chunk you know what to place. (item IDs, correct rotation)
It is best to use array maker for this as it has array list Tables.

Also what krmko mentioned is correct. there is a system setup that disables blocks that are surrounded by other blocks on all directions.

I am not sure what the best approach would be to check this (raycast?, array table loop?, Triggers? other way?)
Title: Re: How to instantiate a Game Object ?
Post by: Fat Pug Studio on May 27, 2019, 08:10:43 AM
Really depends on the size of the world, number of cubes and visibility distance. I presume he uses raycasts ot detect where the cube will be placed and the instantiates them, which is a no-no, only spawning. Chuck solution seems the best, chunk activates on distance from player, doesn't need to be anything more dynamic than that.