Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / Can AGK create more than 100000 cubes from for loop?

Author
Message
Yiu435
3
Years of Service
User Offline
Joined: 19th Dec 2020
Location:
Posted: 11th Aug 2023 09:16 Edited at: 11th Aug 2023 13:58
Here is my problem.
If I add Create3DPhysicsStaticBody(objectid) to my code, and run a 100x100 for loop to create group of objects, my app will be out of memory and close with no error message.


The test file is attached.

Attachments

Login to view attachments
Aidan
User Banned
Posted: 11th Aug 2023 09:25 Edited at: 11th Aug 2023 09:26
Not like that, your FPS will grind to a halt you need to build cubes on a mesh instead using meshmemblocks . Your way is
do able but bad practice

There are loads on here in the classic forum to create something with loads of cubes.

Just search for meshmemblocks
Yiu435
3
Years of Service
User Offline
Joined: 19th Dec 2020
Location:
Posted: 11th Aug 2023 09:27
@Aidan
Thanks, I wil create a new thread cause my title is wrong
Virtual Nomad
Moderator
18
Years of Service
Recently Online
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 11th Aug 2023 12:55 Edited at: 11th Aug 2023 12:58
Yiu435,

we can change thread titles; just ask

otherwise, based on your edits, this may help? Silent Crash with 3D Physics Objects > ~1,000 which you may have already found.
Yiu435
3
Years of Service
User Offline
Joined: 19th Dec 2020
Location:
Posted: 11th Aug 2023 13:20 Edited at: 11th Aug 2023 13:26
@Virtual Nomad
Yes,I found my problem on the command Create3DPhysicsStaticBody(objectid).
If I add Create3DPhysicsStaticBody(objectid) to my code, and run a 100x100 for loop to create group of objects, my app will be out of memory and close with no error message.

The test file is attached.

Attachments

Login to view attachments
Aidan
User Banned
Posted: 11th Aug 2023 13:32
Yes it will cause creating cubes I understand. 100x100 cubes will be heavy on vertexes...

Like said before, try your code with mesh memblocks.

I'll find some code later on for you as an example. I've seen some somewhere on creating cubes with a mesh. Cause this will drop the FPS if have one drawcall to the GPU instead of 100x100 draw calls

I'll have a look round later today
Yiu435
3
Years of Service
User Offline
Joined: 19th Dec 2020
Location:
Posted: 11th Aug 2023 13:39
@Aidan
Thank you.

I already found the error command which is " Create3DPhysicsStaticBody(objectid)"
if I remove this code from my 100x100 loop, the output will be normal, otherwise, it will crashed.
The test file I have attached on above reply.
Aidan
User Banned
Posted: 11th Aug 2023 13:47
Ok cool. I understand.

Having a physics applied to a large mesh won't work cause it is in affect 1 object. But you wish to have physics to all objects.

How about decreasing the amount 100x100 to 10x10 and keep increasing to 20x20 then 30x30 etc and see how many can take before it runs out if memory and will that's perhaps do?
Yiu435
3
Years of Service
User Offline
Joined: 19th Dec 2020
Location:
Posted: 11th Aug 2023 14:06
@Aidan
under 10x10 will work but it will be hard to handle if I want to create a large map for my project
Aidan
User Banned
Posted: 11th Aug 2023 14:22
Let me do some thinking. in the mean time, let others see what they suggest
Aidan
User Banned
Posted: 11th Aug 2023 16:10 Edited at: 11th Aug 2023 16:11
Quick question

So you really want 100x100 cubes / objects visible with physics viewable to the screen all at same time cause if you don't. You should be able to turn off physics for all objects that is not on the screen. Inside the frustum field of vision as such

Surely you don't want 100,000 cubes on the screen at same time

I haven't looked at code cause I'm working off a mobile and I don't have AppGameKit to fully test or change

Maybe have to rethink your design
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 11th Aug 2023 18:19 Edited at: 11th Aug 2023 18:19
I believe there is a limit inside AGK's 3D engine to a little over 1000 dynamic physics objects

https://forum.thegamecreators.com/thread/227616
Automation on Steam now!
Score Table Jr. on Google Play!
Aidan
User Banned
Posted: 11th Aug 2023 19:01 Edited at: 11th Aug 2023 19:49
I thought it may struggle, physics is a heavy task

Could try the frustum idea by use of

GetObjectInScreen( objectID )

https://www.appgamekit.com/documentation-studio/Reference/3D/GetObjectInScreen.htm

This is studio version, not sure about classic

Returns 1 if an object is on screen and 0 if not

If 0 then turn off physics for that object and
If 1 then turn physics back on

Don't know how resources will be but that's my idea

Hope this helps

If I can think of other idea, will let you know

Edit..
Could you send a screenshot of the app your trying to achieve, it will give us more of an idea. Is it like Sand Balls game for example
Yiu435
3
Years of Service
User Offline
Joined: 19th Dec 2020
Location:
Posted: 12th Aug 2023 05:44 Edited at: 12th Aug 2023 05:53
@jd_zoo
yes, it is same problem to me and you, do you find any solution?

@Aidan
I have uploaded a simple test file on the above thread, it just is a very simple test file illustrated the problem.
GetObjectInScreen may not work with Delete3DPhysicsBody (objectID) cause I got the same error result.
Aidan
User Banned
Posted: 12th Aug 2023 08:34 Edited at: 12th Aug 2023 09:51
Try something like this



It's how I would do it, it's the only way I can imagine this working at least unless others have some other thoughts

But then we still will be limited to 1000 as we have found out
Until TGC looks into fixing to have more

And an sorry but I can't do any AppGameKit programming as yet, in working off memory but like to keep mind occupied and if that's helping others then I don't mind

, hope makes sense anyway
Yiu435
3
Years of Service
User Offline
Joined: 19th Dec 2020
Location:
Posted: 12th Aug 2023 11:20
@Aidan
I created an issue thread to github.
Hope the develop team can notice it.
Virtual Nomad
Moderator
18
Years of Service
Recently Online
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 12th Aug 2023 12:53
Quote: "I created an issue thread to github."

it's already a known issue. i'd provided a link to the issue above.
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 12th Aug 2023 20:12
Quote: "find any solution?"


No as noted it is a reported bug, for creating objects I use Get3DPhysicsTotalObjects() to keep it under a hard limit. I keep track of all the dynamically created items and delete the oldest ones when needed

Automation on Steam now!
Score Table Jr. on Google Play!
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 13th Aug 2023 02:40
You might want to try ;
InstanceObject()
PartTimeCoder
AGK Tool Maker
9
Years of Service
Recently Online
Joined: 9th Mar 2015
Location: London UK
Posted: 16th Aug 2023 01:33
even with instancing 100k dynamic objects is asking a bit much of the engine without any kind of batch rendering, my imagination is hard pushed to think of a situation where you need 100k dynamic objects all active at the same time you are going to have to code a smart solution for that one, agk simply does what you tell it there is no optimisation in the background so realistic hard limits must be imposed, if ~1000 dynamics is not enough then maybe you need to rethink your plan.
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee

Login to post a reply

Server time is: 2024-05-07 17:52:59
Your offset time is: 2024-05-07 17:52:59