#Object Pooling
1 messages · Page 1 of 1 (latest)
alright
Learn how to create an object pooling system to reduce processing time and help your game run smoother!
Get the scripts used in this series by supporting on Patreon at:
http://www.patreon.com/gamesplusjames
Get the art asset's used in this episode from Kenney here: http://www.kenney.nl/assets/platformer-pack-redux
Don't forget to hit that lik...
so if i understand this correct. it is working on object1 but not on object2?
oh yeah, im following this from this guy's tutorial
basically the latter will generator
at first, i did only ONE gameobject
something like this
i would keep on using instantiate, but that would create "memory" garbage i guess
why are you getting so many red lines?
that is indeed correct
could you show me your scene please? then i know what i am dealing with
just a sec
it supposed to spawn 2 cyan blocks
but based on "debugging" it only spawns one
the top one, which is the latter code
since i gave the "pooled amount = 5" it should have sufficient resource to get TWO blocks out
alright but the list is showing you have 5 objects
yup, that should be working correctly, since i made 5 objects to be reused again and again
ah like that and then you have it so that it enables 2 of the objects but it only enables one?
correct
i think the issue is with GetPooledObject()
tbh im puzzled. Because i rarely use this pooling method
oh wait i foudn it
so it is quite easy.. you call that function after each other. But!
the mistake you made is that you dont enable the first one. so when you call the second one. it grabs the first one because it is still inactive
there you go this should fix it
what i did this fix this.
GameObject newRoomRight2 = theRoomPoolerRight.GetPooledObject();
was put AFTER the newRoomRight1 was enabled
and since it is enabled theRoomPoolerRight.GetPooledObject(); sees that the first one is enabled. and moves on to the second one
hmm, so that means i shouldnt "grab" both at the start
and instead grab 1 , set active, grab 2 set active
yup it worked
yeah i think so
i mean literally overlapping in the scene
i do think this thread can be archived as the issue has been fixed
Yeah their position is overlapping you mean?
yup
so i might need something to check whether there are any "items" at this location, if yes then dont instantiate, if no, then instantiate
maybe your roomwidth is 0?
nah it's correctly placed at 10
just that my spawn point is based on my character movement
you can check if there is any object around 10f of the object
probably object with "tag" right ?
yes but i would recommend using a layer for this one as they are dungeon rooms right?
it would be best to have the rooms itself as a layer
im just not sure where this thing should go
i have too many scripts that i cant keep track of. But i have a feeling it should be at the RoomGeneratorRight script
yes
probably in this section
maybe something like
if (transform.position dont have any object layer named" platform"
{
then generate platform
}
else
{
do nothing
}
in the same function. what you do is:
RaycastHit2D _Hit = RaycastHit2D(newRoomRight2.transform.position,transform.right * 10f;
if(_Hit)
{
if(_Hit.CompareTag("") //Or layer)
{
//Execture
}
}
if hit , then destroy item, or better, set inactive
this should actually be called to the room left of the room that you are gonna move there
i could deal with the positioning. but i have to get the correct function right 1st
no then move. you dont need to move or enable if there is something else already there
oh, my " RoomSpawnPoint" must always be moving with respect to the character, due to the nature of the room generation
it must move regardless
or else, it might cause the condition where the character and the room generation point to be too far apart
making it seem like no room are spawning near the player
jesus , never thought making these random room generator is that complicated.
and I only started unity less than 1 month ago