#Profiling 101
1 messages · Page 1 of 1 (latest)
You should get something like this
You did not stop?
the game is going rn
yeah its on a menu screen
...
...
.......
.......
Your a potato head. Of course we need to profile the actual game with all the enemies.
Smart ass 😛
Profiling the actual main menu
That was funny
ok gimme a few mins to get to the point with all the enemies
Profiling 101
@nimble flume
Your still playing
Anyhow, this looks more like it
Open up the PlayerLoop, and go down there
Look up the methods that are taking most of the 99% of your time
Why is it still purple?
i paused the game instead of stopping it
Your physics system wrecks your CPU
why
I don't know how you set it up. But there's your problem
You can't do physics on the GPU.
I don't even know why you need physics for a bullet hell game like that.
Normally just colliders would be enough
so how fix
none
so on the bullets
is there a collider2D ?
yes
and a rigidbody?
yes
i would only put a rigidbody on the object that bullets can hit
like your player
bullets dont hit the player
ok i meant the enemy in this case
why would that make it better
rigidbody are expensive
having them one thousends of objects .... kind of a issue
so only the bullets
Or skip them altogether and raycast yourself?
That's how I would do it in DOTS
But don't know if that works in MonoBehaviour style
i thought unity was more powerful than this
we are still taking about a scenario like this?`
yes
And do the bullets ignore collisions with bullets?
yes
With the ignore layer thing right? not in your code?
Otherwise it's colliding constantly with hundreds of its own bullets, and the enemies too.
private void OnTriggerEnter2D(Collider2D collision) {
if (collision.gameObject.tag == "Enemy") {
gameController.score += 1;
GameObject xpOrb = Instantiate(xpPrefab);
xpOrb.transform.position = collision.gameObject.transform.position;
gameController.xpOrbs.Add(xpOrb);
Destroy(collision.gameObject);
}
}```
thats what i have on the saw blades and bullets
Yeah but then when it enters another bullet, it also fires of that code, checks if it's not an enemy and returns.
That will eat your CPU up too
Just let the bullet layer ignore bullets
And the enemies layer ignore enemies
Yeah, but the physics engine calls those methods
And the enemies layer ignore enemies
the enemies dont have rigid bodies
Okay, so you don't have anything with Physics in your game then if you don't fire a bullet?
just the saw blades
and i dont think they are causing the latency because it was going to 0 fps even before i had the saw blades
here is da rat
Show the Rat script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RatScript : MonoBehaviour {
public Rat ratPrefab;
public List<Rat> rats;
float timer;
public GameObject characterObject;
public const float ratSpeed = 0.5f;
private float spawnDelay = 2.5f;
void Update() {
timer += Time.deltaTime;
if (timer >= spawnDelay) {
timer -= (spawnDelay);
spawnDelay *= 0.99f;
Rat instantiatedRatLeft = Instantiate(ratPrefab);
instantiatedRatLeft.transform.position = new Vector2(Random.Range(-20, -11), Random.Range(-11, 11));
rats.Add(instantiatedRatLeft);
Rat instantiatedRatRight = Instantiate(ratPrefab);
instantiatedRatRight.transform.position = new Vector2(Random.Range(11, 20), Random.Range(-11, 11));
rats.Add(instantiatedRatRight);
}
foreach (Rat rat in rats) {
if (rat != null) {
float dx = characterObject.transform.position.x - rat.gameObject.transform.position.x;
float dy = characterObject.transform.position.y + 0.8f - rat.gameObject.transform.position.y;
float t = Mathf.Rad2Deg * Mathf.Atan(dy / dx);
if (dx < 0) {
t += 180;
}
rat.vx = ratSpeed * Mathf.Cos(Mathf.Deg2Rad * t);
rat.vy = ratSpeed * Mathf.Sin(Mathf.Deg2Rad * t);
rat.transform.Translate(new Vector2(rat.vx * Time.deltaTime, rat.vy * Time.deltaTime));
}
}
}
}
That's not this one?
Okay so that's empty
ye
I would delete it, that's still eating CPU
But it's not your Physics problem
I have no idea, you are not giving me anything related to Physics, but it's the Physics system that's killing your game.
idk what to show u
Yeah, and I sadly can not help then
You could open it up more
but this isnt even a big game
Open up those
i just dont understand why unity is struggling this hard, i switched to unity cause i was told it was more powerful
And it seems it's still looking for collisions against other enemies, as an enemy.
So do the layer thing I mentioned
on the rat?
Yeah start with that first.
how i do it
Also make sure the rat has the Layer Rat
It's struggling because you tell it to look for collisions against hundreds of gameobjects with hundreds of gameobjects each frame.
You can shoot 14 million bullets in Unity without lag, if you just optimised it.
can you try enabeling this checkbox in the unity 2D pysics settings?
Edit -> Project Settings -> Physics 2D
ok its on
how do i do the layer ignore thingy
i still dont know why the rats would be colliding with eachother if they dont have rigid bodies
That's fair, I don't know either, but I am concluding 3 things:
The physics system is killing your game
You don't have any gameobjects in your game with a rigidbody
Therefore the only thing that can still cause FindNewContacts physics checks, are the rats with the colliders.
And I don't know the internal workings of a collider without a RigidBody, does the collider call that physics function, or the RigidBody?
If that's true, your whole story makes no sense.
how do i do the layer thing
Then there are rigidbodies somewhere
Add a Layer Rat, set the prefabs to Layer Rat, and ignore matrix Rat x Rat
Or make it Enemies
More generic
where is ignore
In the Unity menu bar, go to Edit > Project Settings, then select the Physics category to open the Physics window.
meow?
ill restart game
Yeah, some stuff resets while playing
il be intrested if the Multithreading is helping
Going to take 10 minutes before hes at the lot's of enemies again
might be worth doing some test setup that allows you to skip to that palce
Totally agree
rip
No idea then 🤷♂️
unity bad
Not at all, like I said, you can make a bullet hell game with millions of bullets in Unity
This setup either does not work, or there is still something calling the physics system that you don't know of
the middle chick has a rigid body but its only 1
Anyhow, you can try to make this in Unreal, see if it goes better
i doubt it will
Or Godot
im just kinda dissapointed
That's more inclined to 2D
how do games like factorio exist with millions of entities
when unity cant even do like 200
You are constantly making that claim, it's not true.
have fun with that game in another game engine and your list of bad game engines will grow long fast
https://streamable.com/zojcj6
Here I have 78404 fully animated models in unity in 3D
That's way more heavy then the stuff you are currently doing. It's also a few thousand times more optimised
Don't say that unity can't handle 200 entities, it's simply not true
It's also a few thousand times more optimised
Well that's a really long story for this example and doesn't really matter for your physics problem.
But I have spend many hours looking through the profiler and optimising everything about this system. This was the best I could get out of it.
So you can do that too, just figure out what's causing your Physics calls. Disable the colliders from the enemies/your saw blades/your rigidbodies/w/e. Just look at it.
There is nothing I can do to help anymore. Good luck with it.
my rats are being put on a spawn timer so the spawn timer continually decreases
what happens when the spawn timer is 0 or negative and its trying to spawn rats every frame
It's your code, you tell me
what
I have no idea how you made your conditional check
for what
The spawn timer...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RatScript : MonoBehaviour {
public Rat ratPrefab;
public List<Rat> rats;
float timer;
public GameObject characterObject;
public const float ratSpeed = 0.5f;
private float spawnDelay = 2.5f;
void Update() {
timer += Time.deltaTime;
if (timer >= spawnDelay) {
timer -= (spawnDelay);
spawnDelay *= 0.99f;
Rat instantiatedRatLeft = Instantiate(ratPrefab);
instantiatedRatLeft.transform.position = new Vector2(Random.Range(-20, -11), Random.Range(-11, 11));
rats.Add(instantiatedRatLeft);
Rat instantiatedRatRight = Instantiate(ratPrefab);
instantiatedRatRight.transform.position = new Vector2(Random.Range(11, 20), Random.Range(-11, 11));
rats.Add(instantiatedRatRight);
}
foreach (Rat rat in rats) {
if (rat != null) {
float dx = characterObject.transform.position.x - rat.gameObject.transform.position.x;
float dy = characterObject.transform.position.y + 0.8f - rat.gameObject.transform.position.y;
float t = Mathf.Rad2Deg * Mathf.Atan(dy / dx);
if (dx < 0) {
t += 180;
}
rat.vx = ratSpeed * Mathf.Cos(Mathf.Deg2Rad * t);
rat.vy = ratSpeed * Mathf.Sin(Mathf.Deg2Rad * t);
rat.transform.Translate(new Vector2(rat.vx * Time.deltaTime, rat.vy * Time.deltaTime));
}
}
}
}
So it spawns every frame then?
so is that whats causing it?
This isn't a physics thing is it?
no
And we concluded that your problem was a physics thing
but we already established we cant find anything physics related
I understand what's happening, that's not the issue. You still haven't said to me what's making all those physics calls. You need to figure that out. I already gave you a few ideas how, good luck with it, I'm going to bed
