#archived-code-advanced

1 messages · Page 130 of 1

hybrid tundra
#

I know what is eating memory

#

textures in the memory

#

but the main issue is not just these

#

the main issue is that these are stay in the memory even when the whole scene gets unloaded

untold moth
#

30-40% is not too bad for textures.

hybrid tundra
#

~200 textures left in the memory after I unload the complete level

hybrid tundra
#

and nothing else

untold moth
#

Then they should be 100%, no?

#

Or I don't know. How do you define if it's a problem or not.

hybrid tundra
#

that's how I define its a problem

untold moth
hybrid tundra
#

so, if scene unloading is not freeing up memory from textures, then what?

hybrid tundra
#

I wrote percentage wrongly

#

lets focus on textures left in memory

untold moth
stuck plinth
#

iirc TMP just uses Resources.Load internally, maybe UnloadUnusedAssets is what you need?

untold moth
#

How are they loaded? Are all 200 textures TMP related? That doesn't sound normal

#

I don't see any profiler data shared.

#

Also, when you're talking about 30-40%, how much is it in MB? Are we talking several GB? Several hundreds of MB?

hybrid tundra
#

4gb is texture memory

#

what I see is that they stay referenced in materials

untold moth
#

Are we talking RAM, VRAM? Or is it unified memory platform?

hybrid tundra
#

so the textures are still referenced from materials

#

after I unload the scene

untold moth
#

Then the materials are still loaded

hybrid tundra
hybrid tundra
untold moth
ebon abyss
untold moth
#

How are you even trying to optimize memory without knowing if it's RAM or VRAM? lol

ebon abyss
#

If it's mobile or other integrated graphics it doesn't really matter

#

But yeah use the actual memory profiler

untold moth
#

Investigate the chain of references. The issue is likely the objects that hold the reference to these textures.

ebon abyss
hybrid tundra
#

and textures are leaking

hybrid tundra
#

at least Hierarchy window doesn't show them at all

untold moth
#

Are these objects instantiated at runtime? Loaded in some non standard way? Are they DDOL? There are so many factors and you have barely shared any info.

echo coral
#

TMP textures often remain loaded always (especially if used in the global fallback list)

untold moth
#

If it's really what's happening, it's easy to confirm in the profiler.

ebon abyss
#

Are you using additive loading?

untold moth
hybrid tundra
hybrid tundra
#

at least not in the Hierarchy

#

Memory Profiler shows me textures which are pointing to gameobjects, which are not existing in Hierarchy at all

untold moth
#

The hierarchy is not your whole game memory you know.

hybrid tundra
ebon abyss
untold moth
hybrid tundra
#
  1. probably cached enemies, so maybe there's a script containing references to them, but I don't know then why those have real names, not just "null"
untold moth
hybrid tundra
#
  1. I'm still investigating, and I'm also under NDA
untold moth
#

You wouldn't see "null" entries in the memory profiler, as it would mean they don't exist, which would contradict them being in the profiler, right?

hybrid tundra
#

but I also know gameobjects like those are theoretically cleared up already

untold moth
#

And see what's referencing them. Or if they are marked as don't destroy

hybrid tundra
#

that's referencing a gameobject which not existing theoretically at that time in the build

untold moth
#

So there you have it. It's in the asset bundle.

#

How are you loading the asset bundle? Are you unloading it when you don't need it?

hybrid tundra
untold moth
#

Then you'll need to research that. I'm not that knowledgeable with the asset bundles myself, so you'll need to look at the docs.

stuck plinth
stuck plinth
#

if bundles aren't unloading as expected, maybe you have a reference count that's not being decremented, make sure anything you're loading with LoadAssetAsync etc is being released properly

#

there's a profiler module for checking the reference counts

hybrid tundra
#

the reference count thing

stuck plinth
#

this one!

hybrid tundra
#

during profiling

echo coral
#

you need to have done a local build with a report for it to work

#

The way i usually test using this is a local build then play using "Use existing bundles"

jaunty compass
#

although i change local rotations to match the player orientation and seat orientation, the rotations end up being different in the scene, messing up my player

#

is there some weird discrepency how unity handles rotations

hybrid tundra
cold kernel
#

Hello everyone, I would love to generate icon images from the icons of my computer files.
Is there anyone who knows Windows API and could help me in some way with it please?

hybrid tundra
#

what do I need to browse here?

stuck plinth
echo coral
hybrid tundra
#

but how is that file called?

echo coral
#

it will find it itself but it should match the build you are profiling (if in editor should be fine if done recently)

hybrid tundra
echo coral
#

it will make the report when built for any platform

stuck plinth
#

i'm pretty sure it always goes into Library\com.unity.addressables no matter what

echo coral
#

you just need to add it to your reports window for use:

jaunty compass
devout hare
#

(270, 90, 0) and (-90, 0, 90) are absolutely the same rotation. The issue is somewhere else

#

Objects should generally be rotated to match each other using global rotation

#

You should also check what happens if both have rotation (0, 0, 0) and if they still mismatch then the objects' forward vector is wrong

jaunty compass
#

i initially did work with global rotation using
orientation.rotation = playerStateManager.CurrentSeat.transform.rotation;
but the rotation of the vehicle would impact the orientation of the player, and it would only be correct if the vehicle was pointing a certain direction

devout hare
#

Then either of those objects are wrong

jaunty compass
brisk spear
#

anyone have a clue on why the second ReleaseMutex() onwards throw a not owned error?

sly grove
brisk spear
sly grove
#

There are no known bugs in System.Threading.Mutex no

brisk spear
#

I can't debug inside Mutex since it uses external code

sly grove
#

it's 99.9% a bug in your code

#

not a bug in Mutex

brisk spear
#

ye i just cant put my finger on it

#

u can see from the screenshot i even log every wait & release event

sly grove
#

maybe there's more than one WinRecognizer in action?

brisk spear
#

considering changing to named pipe IPC instead of shared memory IPC

brisk spear
fathom geode
#

In the leg mover script, a raycast is fired from the cast position to the step targets to determine the normal of the surface and the new position of the step target. The average of the normals is calculated in the body script and the body rotates in accordance to that average. When the raycast doesn't detect any surface, this means the player is now at the edge of a 90 degree surface, and a raycast is fired backwards from the step target and detects the surface.

#

Function in the leg mover script responsible for setting the values of step targets: ```private void setStepTarget(){
bool hitWall=false;
if(pb.xInput!=0 && Mathf.Sign(pb.xInput)==wallRayDir){
var hit = Movement.castRay(castPos.position, wallRayDir*pb.transform.right, pb.wallLegRayLength,Color.red, pb.level);
if(checkHit(hit)) {
setHitValues(hit);
hitWall=true;

        }
    }   
    if(!hitWall) {
        var hit = Movement.castRay(castPos.position,(stepTarget.position-castPos.position).normalized,pb.groundLegRayLength,Color.red, pb.level );
    if(checkHit(hit)){
        setHitValues(hit);
    } else {
        hit = Movement.castRay(stepTarget.position,Quaternion.Euler(0,0,-wallRayDir*pb.stepRayRotation)*(stepTarget.position-castPos.position).normalized,pb.groundLegRayLength,Color.red, pb.level );
        if(hit.normal!=legNormal){
        setHitValues(hit);
        }
    }
    }
}    
#

Function in the body script for rotating and positioning the body: private void setBody(){ var hit = castRay(transform.position,-transform.up , groundBodyRayLength, Color.red, level); if (hit) { var targetRotation = Quaternion.LookRotation(Vector3.forward,averageLegs); transform.rotation=targetRotation; rb.position = hit.point + (Vector2)transform.up* bodyOffset; } }

#

(Both functions are in their respective Update functions)

#

SOMEHOW I FIXED IT BY PUTTING ONE FUNCTION IN FIXED UPDATE??

#

Before that, the function the raycasts was in the leg logic script's update function, and the setBody function was in the body logic script's update function, and instead i made setBody to be in fixedUpdate

#

How did this work?

minor ruin
#
var relativePos = transform.InverseTransformDirection(target.position);
relativePos.x = 0;
var targetPos = transform.TransformPoint(relativePos);

transform.LookAt(targetPos, transform.up);```

why does this only work when im moving the camera?
#

this is how the Hierarchy is setup

long ivy
#

well one glaring issue is that you're feeding a world position into a method that is looking for a direction

sick rapids
#

On fresh boot of a unity project, what is your memory footprint? Just looked and mine is 9gigs fresh, technically down from 11 at startup (after letting it settle). This seems abnormally high, and I'm curious if there's a way to see where all that memory is

#

The project is a 2d project only a month in, no use of the resources folder

#

I do have 64gb of memory on my pc, idk if it just eats more because it can

#

Perhaps someone can help me read this, or post their own for reference?

hybrid tundra
#

can the AsyncOperationHandles cause a memory leak, if I use Addressables.LoadAssetAsync and storing the handles only in local variables?

compact ingot
hybrid tundra
compact ingot
#

typically such types would implement IDisposable

hybrid tundra
#

thanks

stuck plinth
untold moth
# sick rapids

Looking at the processes, the editor itself only eats 2.5GB. 3.5 GB is your IDE. 960 - profiler, then some other extra editor processes for 1600, dotnet runtime, and some other minor stuff, like MSBuild and compilers.

untold moth
untold moth
# sick rapids

Untracked is usually reserved memory. If the editor releases some of the allocated memory, it would usually not release it to the system but keep it reserved for future allocations. Because requesting memory from the system can be expensive performance wise.

ebon abyss
#

But yeah this doesn’t look like a lot

compact ingot
# hybrid tundra can you rewrite this sentence with more simple words?

if you create the handle with new AsyncOperationHandle() and store them in a local variable and otherwise do nothing with them, you will not produce leaks, even if you do not release them since no resource is associated with that handle. If you get them from a member of the Addressables API, they will probably be associated with a resource that will need to be released when no longer needed to avoid a memory leak.

hybrid tundra
#

the latter part

#

@compact ingot can I use Addressables.Release with the asset name as well?

#

as I read, it works only with the actual object, not its name

echo coral
#

you mean address? I think you can only release with the asset or the handle.
My workflow is to release the assets, either by some component handling the load or a single handler that loaded many objects.

e.g. for loading a sprite to display:

icon = await Addressables.LoadAssetAsync<Sprite>(item.spriteAddress);
if(image != null)
{
   image.sprite = icon;
}
else
{
    //If UI image were destroyed mid load
    Addressables.Release(icon);
    icon = null;
}
sick rapids
sick rapids
ebon abyss
#

No it's because I'm making an open world game and also the engine has a memory leak 🙂

#

I also keep the editor open until it crashes, which usually takes 2 - 3 days

gloomy nova
ebon abyss
gloomy nova
#

I pretty much only use gameobjects for representing things in the actual engine, all the game logic happens in code that's otherwise removed from Unity

hybrid tundra
#

do someone know how to use memory profiler?

ebon abyss
#

Yes

#

Someone knows how to use the memory profiler. Now ask your question.

hybrid tundra
#

but the material still be in the memory

#

can I somehow forcely release that memory?

#

should I override OnDestroy on the script in the gameobject

#

and when that gets called, should I set the Renderer's material to null?

ebon abyss
#

Unity doesn't release loaded assets until Resources.UnloadUnusedAssets is called.

ebon abyss
#

Are you profiling a build or the editor?

hybrid tundra
#

but I gave this task up for now

#

based on the two profilers, there are unexisting assetbundles referring to some textures (addressable asset profiler doesn't show me those at all, memory profiler still referring to some weird blablah named addressable bundles)

#
  • there are other references as well
#

like memory profiler tells me that there are gameobjects actively holding those materials inside ParticleSystemRenderers

#

but I manually cleared those, nullified those materials, called Resources.UnloadUnusedAssets, and still nothing was freed up

dusty wigeon
dusty wigeon
# hybrid tundra I know

If you use addressable, memory wont be release as long as another object in the bundle is still referenced.

echo coral
hybrid tundra
# echo coral Memory profiler helps to find what textures are loaded and also helps you find l...

sorry for pinging you again, maybe I can do it, because you also did it.
But the issue is that I had like 13 addressable bundles stuck in memory, I cleared up those, I had only 3 (and those are containing only 6-7 materials. But the texture memory got increased.
I checked the memory profiler, and for some textures it shows that its referenced from 2-3 places, for some it doesn't show addressables, it just show me some gameobjects, which are not loaded anymore. Some of them has child objects with ParticleSystem components, their Renderer has the materials, which should have been unloaded. But even the gameobjects are invisible in Hierarchy view.
Tried to add a script to the parent to find all ParticleSystem children and set null to the materials and sharedmaterials of these child ParticleSystems, I also tried to use Resources.UnloadUnusetAssets (or whatever it is called), but the memory was still the same.
Some of these textures are also referenced by some asset bundles, which have a name with random letters and numbers, and those are not visible in the Addressable Asset Profiler at all. But only a small percentage of these textures are still referenced by these "ghost" addressable bundles.

echo coral
hybrid tundra
#

but based on what I wrote there are textures, which are yeah, used by some kind of unexisting addressable bundles, but they are also used by other things

#

I wanted to figure out how to get rid of those other things I mentioned

echo coral
#

Share screenshots of this if you can.
If you load a texture directly with addressables and keep a ref to it but release it, only the managed shell survives, the texture data is still unloaded from GPU memory.

#

So you need to not confuse yourself by looking at the managed shell only. The profiler should tell you if it's a leaked managed shell

hybrid tundra
#

only tomorrow

echo coral
#

Don't bother then. When I debugged similar issues I mostly used the profiler to tell what textures were loaded but I understood what was loading them in initially so releasing correctly was easier

hybrid tundra
#

I will bother, because I need to solve this issue asap

#

and yeah, it would be easy, if I would see through all of the project

#

and the million source codes

#

because I just got into the project, and don't really know most of the source code

echo coral
#

There are editor functions to get asset dependencies too

hybrid tundra
#

I will check these tomorrow

#

I will go to sleep in 10 min

echo coral
#

Sometimes an asset you didnt think depended on something infact does (prefab variants have some weirdness with deps)

quaint bloom
#

Hi ! I have a question regarding cinemachine. Is it possible to create a freeloock camera, that focus on multiple target ?

#

and also, can I know via code if a target is inside or outisde the camera frustum ?

quaint bloom
#

nevermind I found out UnityChanFrustrated sorry sorry

hybrid tundra
#

@echo coral I have collected the main things I can see in Memory Profiler and Addressable Assets Profiler. Please go from page 1 to page 4, because my comments are mentioning parts from previous images.

hybrid tundra
echo coral
# hybrid tundra

If you check the built addressable assets (Library/com.unity.addressables/aa/{platform here}) do you find a bundle with that filename? It doesnt make much sense for a bundle to magically exist and be in use that isnt real. You can change your group settings to make the local bundles keep their group name and not be hashed.

When you load your menu, go elsewhere then back to the menu, do the handle counts go up? Those are things that never get released properly and should be looked at

Remember you need to release any loaded asset or any InstantiateAsync() gameobject instance. Unity are dumb dumb and dont make these instances release themselves on destroy. It can be easier to load a prefab and instantiate the old way so you just have to release 1 thing (the prefab asset).

hybrid tundra
# echo coral If you check the built addressable assets (Library/com.unity.addressables/aa/{pl...

None of the addressable bundles have names starting with 8b4972 etc., all of their names are starting with normal english words. I can only see the bundles which are also in the Window - Asset Management - Addressables - Groups.
"You can change your group settings to make the local bundles keep their group name and not be hashed." where?
"do the handle counts go up?" You can also see that in the screenshot that yes, it goes up. But again, if you check my images I've sent, those are containing only those 7 materials, and that's needed for the main menu. It doesn't contain any gameplay related things. So I doubt this would be an issue. The Memory Profiler shows those FX stuff you can see on the images, that's much more suspicious.
About releasing, I theoretically made everything to be released. But there are like 30-40 different classes which does the addressable loading. Why? I don't know. I don't even know when should certain addressables loaded and when should be unloaded. Maybe I've setted the Release part to everything, but I can't be sure, because everything refers to everything.

echo coral
#

groups can produce many asset bundles so stop looking for a 1 bundle for 1 group...
Those "leaking" materials depend on textures surely? It will cause their dependencies to stay loaded forever too

hybrid tundra
echo coral
#

Okay so what assets can you tell so far never get released? Is it those 7 materials?

#

Did they get loaded by you or are they dependencies of another asset?

#

e.g. you loaded a particle system prefab which uses a material

hybrid tundra
#

who to trust? I don't know

#

but Addressable Assets Profiler is experimental profiler module, so maybe I can trust more in Memory Profiler?

echo coral
#

TRUST BOTH

hybrid tundra
#

honestly, all I can see is the screenshots I've sent

#

I can't see anything else

#

and I don't really understand those screenshots to be honest

echo coral
#

Look i can load 1 material with addressables via Addressables.LoadAssetAsync<Material>("MyCoolMat") but it could use 10 textures.
Addressables is showing "MyCoolMat" has 1 handle and ofc the memory profiler shows the 10 textures loaded in for it.

#

So until i release "MyCoolMat", those 10 textures are never going to be unloaded

hybrid tundra
#

one thing is for sure, if you check the images, the gameplay materials, which should not be in the main menu, are not even referred by addressables

#

you can see that in the screenshots

#

this is why I'm confused

echo coral
#

look figure it out yourself ive said enough

hybrid tundra
#

O.o

#

am I look like I'm arguing with you?

echo coral
#

ive said all i want to and i cant help any more

hybrid tundra
#

don't really understand why are you pissed off, but ok

hybrid tundra
#

Addressable Assets profiler shows 7 materials, but those are only main menu materials

#

FX stuff are inside fully different materials

#

I've checked it

#

those materials name are starting with "fx_"

#

I have zero idea why you're offended...

#

I appreciate your help, and I'm thankful, and its just a discussion about what can be the issue... but I'm really trying to say that one profiler tells me only main menu materials and other profiler tells me "main menu only" materials AND "gameplay-only" materials

sage wadi
#

Is 150 lines for an infinite layers recursive process good?

compact ingot
sage wadi
#

Real

quaint bloom
#

Hi ! I'm using cinemachine free look with a targetGroup, and I was wondering if it's possible to lock the camera in a certain orbit.
(like if I turn the camera from the side of thoses targets, it stay to the sides of thoses target ; and like if I turn the camera from behind one targets, it stay that way even when targets turn around each other)

#

here's a drawing to better explain it : (if it can help better vizualize what i'm going trought) UnityChanHuh
(here the camera stay & rotate at the side of thoses targets)

compact ingot
quaint bloom
#

it's just that I want to preserve the current orbit when targets move around

compact ingot
#

i have a feeling what you want is not specific enough to be automatable

#

how do you define what the current orbit is?

#

then how would you redefine that when the targets move?

quaint bloom
#

UnityChanThink I tried to get the vector from target A - target b position and compare that to the world position, to then define an offset value to apply when it change.. but I couldn't make it

#

something like :

Vector3 targetVectors = targetGroup.Targets[0].Object.position - targetGroup.Targets[1].Object.position;
float moveAmout = Vector3.Angle(targetVectors,Vector3.forward);    

untold moth
hybrid tundra
#

can you check the page 4?

untold moth
hybrid tundra
#

in the info

untold moth
# hybrid tundra Okay, and what to check for?

All of it. Basic info would tell you if it's referenced and why it's in the memory. Help would explain in more details. Advanced would have advanced info(don't remember what it contains).

hybrid tundra
#

what can you understand from this?

untold moth
# hybrid tundra what can you understand from this?

First is that it's referenced by something. Is there something deeper in the hierarchy?
Then that there are fields on that script instance that could be referencing other objects and preventing the GC from collecting them.

exotic trout
#

Just random thought probably not relevant but any chance prefabs from the bundles (via direct loading or due to being referenced from direct loading) are still lingering in hideanddontsave land? Do those show up in the primary hierarchy in profiler?

hybrid tundra
untold moth
hybrid tundra
hybrid tundra
#

in here, the hierarchy is deeper

#

so what should I see in here?

untold moth
# hybrid tundra

Same with this object. The Help basically tells you what's going on. You need to find what's referencing it.

hybrid tundra
#

is it visible from these screenshots?

#

can you see it?

untold moth
hybrid tundra
untold moth
#

Yes.

hybrid tundra
#

I can't find the ProcGenManager between the Unity Objects

#

so I guess that's the one referencing it?

untold moth
#

It's in the reference chain for sure. However the profiler says that it is referenced once by something.

hybrid tundra
untold moth
#

Right.

#

Did you not read through the memory profiler manual?

hybrid tundra
#

I usually just use youtube tutorials or anything else other than Unity manuals

untold moth
#

Well, if you're asking in this channel, you're expected to have done a minimal amount of research on the topic.

hybrid tundra
#

I mean I know English, but maybe not that much, like someone native speaker

untold moth
#

Many devs here are non native English speakers, yet they have no problem reading the docs. Anyways, you can learn in whatever way you like. I'm sure there are plenty if video tutorials on the memory profiler. Did you not look at any?

#

Anyways, if you can't find that object anywhere in the profiler, it's a good idea to see where it is used in code and whether it's reference is correctly nullified after it's destroyed.

hybrid tundra
hybrid tundra
hybrid tundra
#

you can see that

untold moth
#

It's the other way around. The dictionary is referenced in the ProcGenManager, not the other way around.

#

You need to look where in the code the ProcGenManager could be referenced.

hybrid tundra
#

ProcGenManager is referenced in 84 places in the entire project

untold moth
#

The core of the issue is that ProcGenManager is destroyed, yet still referenced somewhere, so whatever it references(eventually leading to your textures) can't be released either.

hybrid tundra
#

aaaaaaaaaaah

#

okay

hybrid tundra
#

and by the way

#

ProcGenManager is a MonoBehavior

#

if t:ProcGenManager filtering doesn't give back results when returning to main menu

#

then how could it still be referenced?

untold moth
untold moth
hybrid tundra
#

and even if I modify all 84 places

#

then still that won't be 100% sure to get a meaningful result in the memory

untold moth
#

Learn to look at the references window more efficiently. You only need to look at each separate class that references it. I'm sure there aren't 84 classes that reference it. Look at where it is assigned to class fields.

#

Ideally, make sure it's not assigned to class fields in many objects, just in one or a few at most.

hybrid tundra
#

and it gave me 71

untold moth
#

For example, here I have 13 references to a class in my project, but with a quick look at the list, I know that I only need to look at these 4 places.

hybrid tundra
#

but Unity itself wrote 84 references above the ProcGenManager class header

untold moth
#

What header? Are you doing C++ or something?

untold moth
hybrid tundra
#

in here it writes 84

#

oh okay

#

from your image now I get it

untold moth
#

Again, it's all the places it's refrenced. Not all of them are relevant

hybrid tundra
#

what you've meant

#

okay

hybrid tundra
#

maybe _instance should be destroyed, when returning to main menu

#

right?

untold moth
#

Ok, so it's a singleton. It has a static reference. You need to set it to null when the object is destroyed

#

If it's only supposed to be in one scene, I'd reconsider using a singleton pattern for it, but if you really want to, maybe try setting it to null in OnDestroy. Or if that doesn't work, on scene transition.

hybrid tundra
#

I mean it seems to me that its just not used correctly

#

ok, thanks

#

one other thing I have recognized

#

is that some textures have setted Read/Write to Enabled

#

but the project doesn't contain Texture2D.SetPixel or SetPixels

#

so I guess these Read/Writes can be Disabled safely, right?

untold moth
hybrid tundra
untold moth
#

Yeah. It's always good to ask whoever is responsible for it of their intention.

hybrid tundra
#

okay, thanks very much for today's help

#

I really appreciate it

#

can the textures enable Read/Write by default during importing btw?

#

or it required from someone to manually set some of these to Read/Write Enabled?

untold moth
hybrid tundra
#

:/

hybrid tundra
#

so I can be happy, because there are cases apparently, when its enabled by default

#

and then I could disable it

austere kayak
#

Hi guys, I got a problem, I got laser GO (through LineRenderer) + BoxCollider set to trigger, but the laser can push player when hit

#

the lasers are rotating around the Boss

hybrid tundra
austere kayak
#

nono

hybrid tundra
#

then add it 🙂

somber charm
#

Hey anyone free for a call today? I've got something really interesting

plush hare
#

these channels aren't for private help regardless.

somber charm
#

I've created a system in Unity that does not use procedural logic. It's a new way of thinking. I want to walk someone through my system and see if they can grasp the shift.

plush hare
#

You should just post it here

somber charm
plush hare
#

No offense, but unity has hundreds of thousands of daily users. I doubt you've figured out a new and groundbreaking way to use the engine.

#

Unity uses C# which is typically used in OOP settings. So I'm not sure what you're talking about with procedural logic.

somber charm
plush hare
#

Just post your question. Nobody is going to ridicule you

somber charm
plush hare
#

👨🏿

thin mesa
somber charm
plush hare
#

That person probably is here, you're just choosing to be difficult.

long ivy
#

I can't speak for anyone else, but for me it just sounds like you have no idea what you're talking about

plush hare
#

Nobody wants to hop in a call with a random person. Especially people that do know their shit.

somber charm
plush hare
#

Good luck

somber charm
thin mesa
somber charm
somber charm
plush hare
#

You're in the best place to discuss unity topics. Again, you're just choosing to be difficult.

#

You will not find a better community to discuss unity.

thin mesa
#

intentionally being vague about this and refusing to elaborate publicly is going to pretty much guarantee nobody wants to discuss it with you

somber charm
plush hare
#

lmao

plain abyss
robust pulsar
#

This guy is so funny lmao
Shows up —> claims to have invented a new way to program —> refuses to elaborate —> resists all attempts to converse —> leaves

untold moth
tired fog
cedar anvil
#

right now all youve said is "I created a new type of system", you should at least elaborate a little on what it really is

plain abyss
cedar anvil
#

shucks

#

I was going to ask what the motivation for eliminating conditionals is

#

what could possibly be a better solution than if(a < b) { ... }

plain abyss
#

It is a thing, Declarative Programming. Potentially they re-discovered functional programming through Linq and delegates:
https://en.m.wikipedia.org/wiki/Functional_programming

It is a useful paradigm for some applications but very well researched and definitely not a new discovery

In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map values to other values, rather than a sequence of imperative statements which update the running state o...

#

The Lisp language is like the crab of the programming world.

At a certain level, every language evolves into it

compact ingot
# cedar anvil what could possibly be a better solution than `if(a < b) { ... }`

depends on what your goals are. if you want to minimize complexity, everything is better that doesn't create a state machine. declarative programming's idea is that if you declare the desired outcome precisely enough, the solution of how to get there is obvious and deterministic. Meaning you don't need to write procedrual logic as everything that needs to happen is defined as necessary by declaring what solution you want. Note a declared solution is a function, not a value.

peak badge
#

There seems to be a bug in Unity's render pipeline where floor of negative 0 becomes -1 instead of 0. I think.

peak badge
#

not -0.5. Floor of -0

compact ingot
#

same

peak badge
# compact ingot same

Signed zero is zero with an associated sign. In ordinary arithmetic, the number 0 does not have a sign, so that −0, +0 and 0 are equivalent. However, in computing, some number representations allow for the existence of two zeros, often denoted by −0 (negative zero) and +0 (positive zero), regarded as equal by the numerical comparison operati...

#

-0 and +0 are supposed to be equivalent, which means floor(0) and floor(-0) should also be the same

compact ingot
peak badge
#

I see. So you are saying that Unity spec is that floor(-0)==-1. Then which function would you use to first turn -0 to 0?

compact ingot
compact ingot
plain abyss
#

I'm pretty sure C#'s float doesn't have signed zeroes

#

What context are you running into this from?

peak badge
# compact ingot can you show the code that exhibits this behaviour?
const float x_y_factor = 1.5;// Normal hexes are sqrt3.
int xscale = resolution * 6;
int yscale = resolution * 2;
float x = uv.x * xscale;
float y = (1 - uv.y) * yscale;

float t = x_y_factor * x; // scaled y, plus phase
float temp1 = floor(t + y); // (y+x) diagonal, this calc needs floor
float temp2 = (t - y + 1); // (y-x) diagonal, no floor needed
float temp3 = (2 * y ); // scaled horizontal, no floor needed, needs +1 to get correct phase
float qf = (temp1 + temp3) / 3.0; // pseudo x with fraction
float rf = (temp1 + temp2) / 3.0; // pseudo y with fraction
int q = floor(qf); // pseudo x, quantized and thus requires floor
int r = floor(rf); // pseudo y, quantized and thus requires floor

int pX = q;
int pY = q - r;
int temp = floor(pY / float(resolution));
pY -= temp * resolution;
pX += temp * resolution;
if (pX < 0 || pX >= 3*resolution)
    return; // This exit condition is expected to be taken

This is my HLSL shader

plain abyss
#

Ah, shaders. not my division

#

Someone else can handle this one

peak badge
#

Notice in the bottom left corner, the pixels flicker on and off. I think this is likely due to Unity not consistently giving a 0 or -0 (even while paused).

compact ingot
sage radish
untold moth
#

Note that if you're relying on this kind of behavior(signed zero), you might get different results on different platforms too.

#

I also think that it might just be a floating point error issue.

peak badge
untold moth
#

I really doubt a signed zero is gonna appear somewhere naturally without you explicitly using it.

peak badge
#

I'm surprised that the pixels change values even while the game is paused. So unity is doing something unexpected

teal escarp
#

by "game is paused" do you mean "Time.timeScale == 0"? Because that doesn't affect everything 🙂

untold moth
plain abyss
#

If it's a shader issue, it's going to occur even in the editor, so it'll definitely occur in play mode while playback is paused

#

Shaders are always running, even if the game isn't

untold moth
peak badge
#

Correct, but importantly, the camera isn't moving etc. So any rays that are being cast, I would assume would have the same floating point rounding error each frame

untold moth
#

Every time a shader executes it can get a different value due to a floating point error.

untold moth
#

If that was true, z fighting wouldn't exist

teal escarp
#

as I understand it you never get -0 unless you explicitly use it

untold moth
#

Anyways, you'll find all the answers if you just debug your shader.

plain abyss
#

This is probably not going to be something with a quick resolution, there's a whole lot of dark wizardry going on inside of the graphics library and you can't really assume anything to be true. You'd certainly expect something to be the same every frame if nothing moves, but shaders render at the whims of a devious trickster god whose methods are inscrutable and rational behavior is an accident rather than the rule.

peak badge
#

Well, adding a very small epsilon does fix the issue, but I was concerned this just means I'll find a different test cases where the issue reappears (which is now 1 epsilon shifted to the right).

#

int temp = floor(pY / float(resolution) + 0.00000001f); this seems to make it go away, at this resolution

untold moth
peak badge
untold moth
untold moth
#

You'll probably need to research how to output the shader debug symbols in unity.

peak badge
#

I see, it doesn't look too hard, and I have NSight installed. However maybe I will do the practical thing and add an epsilon and move on.

#

Hmm, yeah I will have to debug it. Some of my known error states are fixed by the epsilon, but others aren't. I guess at least I know how to proceed, thanks.

untold moth
peak badge
# untold moth Tell us what it was if you figure it out
int temp = floor ( pY / float ( resolution) ) ;

I used the debugger (and by the way, the hot-reloading of NSight is so much faster than trying to debug within Unity itself).

The issue seems to be this line. At resolution 33, for example, when pY==33, this floating point divide sometimes is 0 and sometimes is 1. Same thing for resolution 74, etc. As we all know, 1/33 is a repeating decimal, as is 1/74.

#

I'll take some recommendations of ways to make this more robust to floating point rounding issues. I'm trying to find how many multiples of resolution is in pY, including negative multiples (which is why I'm using floor).

compact ingot
fathom geode
#
    {
        var targetRotation = Quaternion.LookRotation(Vector3.forward, averageNormal);
        transform.rotation = Quaternion.RotateTowards(transform.rotation,targetRotation,delta*rotationSpeed);
        rb.position = getAverage(stepTarget1.legPos, stepTarget2.legPos) + (Vector2)transform.up * bodyOffset;
    }```
#
private bool setStepWall(float delta)
    {
        if (pb.xInput != 0 && Mathf.Sign(pb.xInput) == wallRayDir)
        {
            var hit = Movement.castRay(castPos.position, wallRayDir * pb.transform.right, pb.wallLegRayLength, Color.red, pb.level);
            if (checkHit(hit))
            {
                 var targetRotation = Quaternion.LookRotation(Vector3.forward, hit.normal);
                pb. transform.rotation = Quaternion.RotateTowards(pb.transform.rotation,targetRotation,delta*pb.rotationSpeed);
                return true;
            }
        }
        return false;
    }```
hybrid tundra
#

Is there a way to make Unity to make a build for PC, when it was cloned from Perforce?
I have enabled Work offline.
No build folder checked out, no Library or anything like this checked out, but still it wants some files badly to checkout to make the build, but it can't since I'm not connecting to the server and build fails for this reason...
If I change the Project Settings - Version Control from Perforce to Hidden or Visible Meta Files, that doesn't solve the issue...

sly grove
peak badge
#

10 resolution widths is well outside the visible screen, so I guess it's "fixed" now.

hybrid tundra
peak badge
sly grove
hybrid tundra
sly grove
#

You're in offline mode apparently

hybrid tundra
plain abyss
#

Well that would certainly explain why it says you're in offline mode

hybrid tundra
#

it was never a question that I'm in offline mode

sly grove
#

Well you need to check out all the essential files in the project before you can build.

#

And to do that you need to be online

hybrid tundra
sly grove
#

Next time you're working in the workplace make sure you download everything you need for a build.

TBH I'm a little confused because is that Unity Version Control or is it Perforce?

I'm used to git where you have the whole project downloaded all the time

hybrid tundra
#

its Perforce

#

this keys file gets generated in this way: PreBuildJSON:OnPreprocessBuild

#

AddressableKeysTool:GenerateJSON ()

#

AddressableKeysTool:Export ()

#

so its not something which is missing

sly grove
sly grove
#

Are you using the Provider API in those scripts?

hybrid tundra
sly grove
#

Well maybe whoever wrote those scripts should be debugging them, or you should ask them for help debugging them.

hybrid tundra
sly grove
#

Yeah and?

My car doesn't have problems unless I drive it in the swamp.

untold moth
peak badge
untold moth
#

You could try adding (0.5 / texture res) so that your uvs are in the middle of a sampled pixel.

#

This way the floating point error is not gonna matter.

#

Unless using a very huge texture.

#

The issue is that you're basically checking the corner of a pixel. You'd totally get into the same issue on CPU and in any other language or scenario that uses floats.

peak badge
#

I think you're misunderstanding the problem. The code is a conversion from [0..1] UV space to integer coordinate Hex space. https://www.redblobgames.com/grids/hexagons/implementation.html for a detailed description, and code snippets.

Adding 0.5 to the UV coordinate just shifts the problem that much to the right. The problem is not the relationship between UV and hex coordinate, the problem is the hex coordinate generated when the pY is equal to the Resolution (at which point, I want to wrap it by -Resolution, and sample a second texture). The wrapping is inconsistent, because sometimes when pY==Resolution, then int(Res)/float(Res) == 0 or 1, depending on some kind of quirk.

#

The hexagon's pY is correct, the problem is the float division to determine if we're ready to wrap. And only when the Resolution would create a certain kind of repeating decimal (1/33) (1/72), etc. The fix of shifting all the numbers positive, and doing integer division instead of float division, removes the quirky behavior.

#

pY is an integer, exactly equal to Resolution (33 in this case).

#

so it's 33/float(33) which produces the occilating result randomly each frame.

#

Since 33/float(33) has no variables, you should expect it would always produce the same result. It doesn't, which implies perhaps something about how this specific shader compiles, such that something like a carry bit isn't reset

#

if that was the case, then you'd be right that it's probably not Unity's fault, though I can't exactly figure out why it happens.

#

Unity controls the only variable: the UV coordinate

#

I don't think the UV coordinate has anything to do with the problem, and it's related to float precision.

untold moth
untold moth
#

Adding half pixel size in this kind of scenarios is a very common practice in shader code.

peak badge
#

Yup, I'll show you the relevant code:

float q = floor(qf); // pseudo x, quantized and thus requires floor
float r = floor(rf); // pseudo y, quantized and thus requires floor
    
int pX = q;
int pY = q - r;

int temp = floor(pY / float(resolution));

temp will get how many times resolution goes into pY. This tells us which texture to pull from (the 0th texture, 1st texture, etc).
You will notice q and r are floats, however they are quantized to an integer.

#

Adding 0.5 before quantization will only mean that the problem appears 0.5 cell units to the right. It still gets quantized, and thus would have the same problem.

#

remember, it's not a single pixel which has the problem, it's the entire cell, which is several pixels wide

untold moth
#

not 0.5. Please don't distort my words. Half of the pixel resolution.

peak badge
#

The output texture is 1920x1080 (it is just a rectangle which takes up the full screen). So say that I bump it by approximately 1/resolution in each direction.

untold moth
#
float pYMid = pY + (0.5 / resolution);
int temp = floor(pYMid / float(resolution));
peak badge
#

resolution in this case is the cell resolution, rather than the screen size. The Hex resolution is about 198x66

untold moth
#

I was never talking about screen resolution. It's the resolution of whatever discreet scale you're working on.

#

Anyways, try it out and see if it stops the jittering.

peak badge
untold moth
#

Great. This is one way people deal with this kind of issues in shaders. Whether you do this or something else is up to you though.

peak badge
#

Yeah now I have 2 solutions. I will benchmark for which is faster

#

It was kind of a surprising sidetrack. I usually tested on resolution==100 but I tried resolution==300 which had this issue, as it does not represent well as 1/300.0 -> 0.0333334f (or maybe 0.033333f, randomly)

peak badge
#

Also big thanks goes to Red Blob Games for their great guide on hex shaders.

tawny otter
#

Anyone know if there is a way to inject an async operation at the front of the queue? Addressables.UnloadSceneAsync to be exact. In our project we need to preload levels with Addressables.LoadSceneAsync(..., activateOnLoad:false) and are running into the issue mentioned in the docs that this blocks the whole async queue until the levels are activated.

old swallow
#

How do I use resolveTarget and RenderBufferStoreAction.Resolve to resolve to frame buffer?

I am using RenderContext.BeginRenderPass(...) path to render eficient deferred shading with MSAA support, but currently it only works when rendering to textures with and without MSAA and frame buffer with no MSAA. I see that AttachmentDescriptor has a separate input for loadStoreTarget and resolveTarget. Could this mean that I render to memoryless buffers with MSAA (like my world normals and other gbuffers) and then resolve to the frame buffer?

I tried to set resolveTarget to BuiltinRenderTextureType.CameraTarget but just got warning "Ignoring color surface store action as it is memoryless". After making a temporary RT and plugging it into loadStoreTarget its rendering again, but only to the RT. No resolve is happening!

Is there any documentation on how to use RenderBufferStoreAction.Resolve or any examples???

hybrid tundra
#

the same textures are leaking

peak badge
#

Ondestroy: if not null, object.remove

#

I forget the exact function calls

#

If you don't, then you will leak GPU memory

old swallow
#

Usually its Dispose or Release

#

one of them is a call to the other

#

check the source its on the C# side

hybrid tundra
hybrid tundra
untold moth
#

I mean, it should be obvious at this point - rinse and repeat.

#

I'd also confirm with a debugger that OnDisable is actually being called in your scenario.

coral schooner
#

Question about Unity.Properties API with Code generation.

I noticed that the generated code for anything with an Attribute uses reflection to add the custom attributes in the property class contructor. But since public fields don't need any attributes to generate the property bag it avoids the reflection call.

However, properties do require the [CreateProperty] attribute, which then triggers the reflection call to add this as a custom attribute.

Is there any way to avoid this or should I just not care about the performance of these one time only reflection calls?

hybrid tundra
#

this is what I'm saying

#

if it would have been solved in this way, then I would not have any questions related to this

#

but it was not solved with this method I mentioned

#

but its 2 am here, I just woke up for a sec

untold moth
# hybrid tundra its still leaking

You mentioned textures and nothing about the manager object.
If it still leaks, then it's probably not collected by the GC properly.
Did actually confirm that OnDisable is getting called when you transition back to the menu scene?

hybrid tundra
#

so going back to sleep

hybrid tundra
#

when going back to main menu

untold moth
hybrid tundra
#

but please think for now that it gets called

#

because I have very limited time to deal with this issue

#

but its needed

#

so I would be happy i you would still provide me some suggestions

#

which I can test out during working hours

#

going back to sleep

untold moth
#

If you can confirm that it's still in the memory despite being set to null, then either something else holds a reference to it, or the gc didn't collect it for some reason. You could try forcing a GC collection manually and see if that helps

thin mesa
#

!collab 👇

thorn flintBOT
#

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
Collaboration & Jobs

thin mesa
#

make a game wit me
that's literally collaboration

untold moth
#

This is not a social chat server for making friends.

#

We're all enemies here.

hard zephyr
#

@thin mesa it dose not say that man

thin mesa
hard zephyr
#

yeah yeah save it for the judge

hard zephyr
hybrid tundra
hybrid tundra
# hybrid tundra

@untold moth maybe this one particular thing was solved, seems to be missing from the current references

untold moth
hybrid tundra
#

tried to set the TileConfig to null in MultiplayerManager

#

so far it didn't get removed

#

but now I make a new build with Resources.UnloadUnusedAssets added after it

untold moth
# hybrid tundra

It has something that references it. Don't you see that there's something deeper in the hierarchy?

hybrid tundra
#

I think only the MultiplayerGame is the point where I can do something

exotic trout
#

If it's referenced in SaveDataManager then it needs to be cleared up if you want to clear it up, no?

hybrid tundra
#

I still don't really get it then

exotic trout
#

Sure but before even getting to that problem, I've been lurking but wasn't this long convo about you not being able to trace down where its still being referenced?

#

if its being referenced there that's that question solved right?

hybrid tundra
#

because SaveDataManager needs to save data from time to time

#

so the only thing which seems problematic to me is that the MultiplayerGame is existing only in gameplay

#

but not in main menu

#

so when we are in main menu, only the things referred by the MultiplayerGame should be cleared up

#

and TileConfig has only 1 reference

#

which is coming from MultiplayerGame

#

so MultiplayerGame should clear up TileConfig when MultiplayerGame itself gets destroyed

exotic trout
#

but if its referenced in savedatamanager, it should be in memory and therefor shouldn't be cleaned up?

hybrid tundra
#

MultiplayerGame itself could stay referenced by SaveDataManager, because that doesn't contain anything else related to textures, only TileConfig

hybrid tundra
#

if its referenced, I don't think its a problem

#

or I still don't understand some basic stuff

echo coral
#

Late to this convo, how much memory is this object using? is it worth fixing this?

hybrid tundra
exotic trout
echo coral
#

If its just the c# objects its not that big of a deal

hybrid tundra
#

the hugest textures are japanese and chinese font atlases

#

but those are not leaking

#

those are just huge textures constantly inside the game

echo coral
#

tmp?

hybrid tundra
#

yeah

#

my issue is that the game should reserve around 1.26 gb of memory

#

and its reserving 2.4 gb

#

because of its leaking (gameplay memory stays in game after returning to main menu)

echo coral
#

If used by fallback fonts they probably get loaded early on and will remain

#

Unity will allocate more managed mem but will hardly ever free it even when its empty

hybrid tundra
#

I just mean 2.40 gb is incredibly much more than it should be

#

and its causing issues

untold moth
hybrid tundra
#

when I select TileConfig

#

it says referenced by 1

#

MultiplayerGame is a child class, its parent class is referencing to TileConfig, but I've cleared that up by setting it null when MultiplayerGame gets destroyed

untold moth
#

Ok, so did you profile after setting it to null?

hybrid tundra
fringe yarrow
#

I downloaded the Unity Open Project Chop Chop, Upgraded it to 6.1 and I'm getting three errors.

Assets\Shaders\Unused\ScriptableRenderFeatures\DepthNormalsFeature.cs(94,5): error CS0619: 'RenderTargetHandle' is obsolete: 'Deprecated in favor of RTHandle'
Assets\Shaders\Unused\ScriptableRenderFeatures\DepthNormalsFeature.cs(17,17): error CS0619: 'RenderTargetHandle' is obsolete: 'Deprecated in favor of RTHandle'
Assets\Shaders\Unused\ScriptableRenderFeatures\DepthNormalsFeature.cs(31,67): error CS0619: 'RenderTargetHandle' is obsolete: 'Deprecated in favor of RTHandle'

However I have no experience and idea how to fix these errors.
Can I get some pointers on how to get rid of these errors?

untold moth
hybrid tundra
#

MultiplayerGame itself is referenced by 9

untold moth
#

Ok, then you need to set it to null in MultiplayerGame.

hybrid tundra
#

MainTileConfig = null

#

and Resource.UnloadUnusetAssets()

untold moth
#

Then it didn't get set to null. At least not entirely.

hybrid tundra
#

inside OnDestroy

untold moth
#

You might be having several instances of MultiplayerGame.

#

Or it's not destroyed

exotic trout
#

(or one instance that remains during the menu?)

echo coral
#

if this is a texture remember that you can Destroy(myTexture) to unload it whenever you wish. The c# texture object will be gc'd later.

hybrid tundra
#

so should I rather modify FX class?

echo coral
#

if you do new Material() you need to destroy those material instances too manually

hybrid tundra
#

nope

echo coral
#

otherwise UnloadUnused should suffice for unity managed material instances

#

Addressables is different but I dont know if this applies here 🤔

untold moth
untold moth
exotic trout
echo coral
untold moth
echo coral
#

so only the "managed shell" is leaking?

fringe yarrow
untold moth
#

I don't remember. I think some objects in the chain are not even destroyed due to being referenced by shell objects.

hybrid tundra
#

ok maybe OnDestroy doesn't even get called for some reason

#

wtf

exotic trout
#

obviously we don't know the ins and outs of your multiplayer setup but a lot of multiplayer setups involve a relevant manager living throughout the main menu too

#

depending on what MultiplayerGame actually does

hybrid tundra
#

I can see it disappearing from Hierarchy

#

when returning to main menu

exotic trout
#

did it move to another?

hybrid tundra
#

t:MultiplayerGame

#

and it disappears

echo coral
#

Aha I wasn't aware that UnloadUnusedAssets() examines managed objects so this does matter. TIL 💡

exotic trout
#

based on my understanding of unity, you have said something wrong

untold moth
#

Hierarchy is not everything...

exotic trout
#

it either called ondestroy or it exists somewhere

untold moth
#

It could be a prefab of addressable or something

#

An asset basically

exotic trout
#

but they saw it leave the hierarchy

untold moth
#

Assets don't appear in the hierarchy

exotic trout
#

yes but

#

they said ondestroy wasnt called

#

regardless of the asset

#

the instance did exist

#

so it either still does or ondestroy was called, no?

untold moth
#

Perhaps it was never in the hierarchy in the first place. Hard to say for sure without more context

hybrid tundra
#

or I'm maybe attaching to a wrong Unity instance

#

with VS

#

or whatever

#

I have 2 PCs and 2 Unity editors in front of me

#

so its quite a complex setup

#

let me test it

exotic trout
#

thats fair, just based on what you've told us though seems like theres conflicting information. if you figure out which part is wrong that will likely help

hybrid tundra
#

okay

#

so OnDestroy gets called

#

but not all of its lines

untold moth
#

Is it an exception/error?

#

And btw, I don't think it's wise to call unload unused assets in OnDestroy

exotic trout
#

I guess this is more a question for me than Tamas but in theory if this gets destroyed due to a scene unloading, the asset cleanup should probably run after all that scene stuff is done right?

#

I know the cleanup happens mostly on demand but surely it tries to clean up after a scene unload

hybrid tundra
#

attempting to use an invalid operation handle

#

because I call base.OnDestroy

untold moth
hybrid tundra
#

that can be because I have added a lot of Addressables.Release previously, but probably placed some of them wrongly

#

because addressables assets are managed by at least 30-40 scripts

#

but that issue is independent from the texture issue staying in the memory now (I think)

untold moth
#

I mean the logic stays the same: investigate in the profiler - it tells you why it's in memory. Fix the issue, test and repeat if it still happens.

hybrid tundra
#

that's okay, I just thought it was setted to null, but still stayed in memory

#

but it seems it was not setted to null

#

the other one was setted (the ProcGenManager)

hybrid tundra
#

but that was not much improvement

#

can't I just clear up the ParticleSystemRenderer's own material and sharedmaterial references correctly?

#

because setting those to null didn't make it disappear

untold moth
#

Check the profiler. They're either referenced by something or set to ddol.

hybrid tundra
#

why its still not enough to get rid of the FX reference?

untold moth
hybrid tundra
#

what the profiler says?

untold moth
#

Didn't we go over these many times by now?

hybrid tundra
#

its so not logical to me honestly

#

the whole References window

untold moth
#

Start by reading the details/info below the hierarchy

hybrid tundra
#

what else should I see here?

exotic trout
# hybrid tundra

(also just because it was relevant last time, did you confirm this code is running?)

hybrid tundra
#

because I have tested modifying this script weeks ago

#

this was the first thing I did

exotic trout
#

i dont understand why that reasoning confirms its running

#

(also i know your just double downing on trying to destroy things as much as possible but if its null before you destroy it the destroy is def. not doing anything)

hybrid tundra
#

I'm panicking, I'm stressful, I just want to finish this

hybrid tundra
#

I'm running out of ideas

exotic trout
#

you could try destroying the materials before setting them to null

hybrid tundra
untold moth
hybrid tundra
untold moth
#

And I don't see you setting these fields to null anywhere

hybrid tundra
#

you think that I try to solve stuff which is pretty obvious

#

but this issue is not obvious at all

hybrid tundra
#

this is where I set those fields to null

#

well not literally

#

but indirectly

#

is that matter if I reach the same materials indirectly or not?

#

getting components or using the already popupated fields should be the same

untold moth
hybrid tundra
untold moth
#

Looking at the hierarchy, there seems to be an array of renderers.

dusty wigeon
#

What is written here:

hybrid tundra
#

@untold moth those ParticleSystemRenderers are exactly the same (receiving from GetComponent) which are already cached in the script

untold moth
#

There is an array field that holds a reference to these.

dusty wigeon
#

Look if any of those flags are set on reference of the object.

hybrid tundra
untold moth
#

That's not the point though

hybrid tundra
untold moth
#

The point is that they can't get collected by the GC, while still referenced

hybrid tundra
exotic trout
dusty wigeon
#

Texture usually does not needs to be collected by the GC to be freed because they are Graphics object. They needs to be released.

untold moth
hybrid tundra
#

I give back my degree

unborn relic
#

Hello,

I am using unity 6000 and terrain trees and infinite terrain.
I want to be able to add monobehaviors to my trees to be able to keep track of the tree's type, hp, state, make it fall, add rigidbody etc.

I know terrain tree's can't have monobehaviours, so what can I do?

My current thought is I need to have a tree manager that subscribes to OnTileGenerated, OnTileEnabled, OnTileDisabled and keep track of every tree instance based on location. I also need to switch terrain trees with prefab trees close to the player (5 meters - ish). Is this doable? WHat are better alternatives?

hybrid tundra
#

is it better?

#

now its a field

#

(but I'm still referring to the exact same components)

untold moth
exotic trout
untold moth
untold moth
hybrid tundra
hybrid tundra
untold moth
hybrid tundra
#

not really trivial

dusty wigeon
exotic trout
#

given thats a instanced component that can't be something to wanna clean up regardless?

#

if im wrong apologies i wont pretend im an expert by any means

dusty wigeon
exotic trout
#

I mean sure but that's not why dlich wanted to ensure they would be destroyed

untold moth
#

Anyways, looking at the profiler details would reveal more.

exotic trout
#

Fair I suppose, though in this case I think Tamas got confused because you advice was on how to destroy the particlesystems correctly and they thought it was critique on destroying those materials and textures better(?)

hope i didn't come off as trying to correct or anything just curious myself tbh 😄

hybrid tundra
#

weird

#

so this is why @untold moth said to manipulate them via the fields, not via the local variables

#

because apparently its very important not to create temporary variables for this

untold moth
#

I mean, this is basic level programming. Asigning a reference to a local variable is not gonna change the value of a field

hybrid tundra
#

I'm a programmer since 2009

#

received my degree in 2012

#

and didn't know about this

#

I've only used c# though

#

never learned c++

#

only in a hobbyist level

untold moth
#

What value is a gonna have in the end of the method?

private int a = 1;

void Method()
{
  int b = a;
  b = 0;
}
#

This is C#

exotic trout
#

dlich what reference did you want tamas to try and clear/unreference/destroy?

untold moth
#

the on'es in the array

exotic trout
#

the particlesystemrenderers right

untold moth
untold moth
hybrid tundra
#

one

#

because its a value type field

#

not a reference type

exotic trout
# untold moth Yep.

Tamas are you aware dlich is suggesting you destroy the particlesystemrenderers themselves and not the values inside of them

untold moth
untold moth
hybrid tundra
#

this is why I didn't understand

untold moth
#

The same behavior is true with refereneces

#
private MonoBehaviour a;//assigned somewhere else, not null

void Method()
{
  MonoBehaviour b = a;
  b = null;
}

same question

hybrid tundra
#

after the method

untold moth
#

no

hybrid tundra
#

why not?

#

its a reference

untold moth
#

References don't have sucha a behaviour

#

You just assign null to a local variable

hybrid tundra
untold moth
#

Then try it out

#

See what the console prints

hybrid tundra
#

or pointing to memory addresses?

#

if I create a List<int>

#

and I give that to a function

untold moth
#

Sort of. But that doesn't change how asignment works.

hybrid tundra
#

and I manipulate that inside

#

then it will still manipulate the same list

#

I gave to method

#

well, I would be very much embarrassed, if I would be a programmer not knowing even the basic stuff

untold moth
#

When you assign a reference to another variable, it's as if you copy the address. So setting it to null just removes the address in that new variable.

untold moth
hybrid tundra
#

both are references

#

and both are assignments

untold moth
#

When you change values in a list, you modify the contents of the list, not the reference to the list.

hybrid tundra
#

but I refer to the same list

#

the method's local variable gets assigned by the variable outside

untold moth
#

When you asign null or a reference to a reference type variable, you say that this variable would point to that object. If you have 2 variables, you can set both to point to the same object or to different objects. Modifying the value of these variables doesn't affect the object itself. Or the other variable.

hybrid tundra
#

same with List<int> a=b;

untold moth
#

This is same, but if you set a = null, that's not gonna affect list b. It's still gonna reference the same list as before.

#

Think of reference variables as just an in64 that contains an address(oversimplification) to the actual object in memory. All the same rules would apply to them as to a value type in this regard.

hybrid tundra
#

@untold moth so to understand, should I set ALL particlesystem references to null in the FX script?

untold moth
#

All the class(or struct if you have) fields, yes.

hybrid tundra
untold moth
#

Read the profiler data. Compare to before. Do you see a decrease in references count? What other metrics are saying? Read it all.

hybrid tundra
untold moth
#

3 different windows?🤔 Not sure what you mean.

hybrid tundra
#

if I select the top T_fx_particleset_01, then it says a material and an assetbundle.
the middle one shows the same
the third one shows two materials

untold moth
#

Then perhaps you have 3 copies of this texture in the memory.

#

I don't know. It's hard to say anything without seeing what exactly you mean.

untold moth
#

You can even see that one of them has smaller memory footprint. Maybe a mip level or just a lower res texture?

hybrid tundra
#

okay, I think in this way I won't be able to solve this task

#

I'm thinking of searching or making an example test project

#

because its unproductive to wait 20 min for every change I make

#

(building takes like 20 minutes even with incremental build)

#

even the scripts are multiple thousand lines long

#

in this project

#

so its even hard to find the fields

untold moth
#

They're usually at the top. But you can also view all the class members in visual studio(or some other ide).

hybrid tundra
#

I'm not effective in this task

#

until now I just wasted time with this

#

maybe I will see something in a test project

untold moth
hybrid tundra
#

and it seemed to be that some addressable bundles as well

#

but no idea which one is reserved, because Memory Profiler only tells me some random character named assetbundles

#

and I can't identify which one is that

#

because its not the real name

untold moth
#

I don't know a lot about addressable so can't say anything about it, but you can usually make some assumptions and infer what asset it corresponds to from other data(like assets that it references/includes and stuff).

dusty wigeon
# hybrid tundra

You potentially have duplicated assets(due to asset bundles) if you are not expecting to have 3 of it.

hybrid tundra
#

I have expected to at least reduce the number of references, but so far I couldn't achieve it

dusty wigeon
hybrid tundra
#

because apparently reference counts didn't even decrease

dusty wigeon
untold moth
hybrid tundra
hybrid tundra
#

honestly

#

this project has so much textures and references

dusty wigeon
hybrid tundra
#

I would have been happy if I could have reduced at least a few

untold moth
hybrid tundra
#

or even more

dusty wigeon
#

What is the status here after your build

untold moth
hybrid tundra
#

and deadline is close

#

and probably there will be other tasks unrelated to this one

#

anyway, making a test project now

#

hopefully I will understand something from that

untold moth
#

Then focus on understanding the issue. Blindly testing different things is just gonna be a waste of time.

exotic trout
#

Not the best solution and I know its roughly 1ish gb of potentially savable memory but is this a make or break problem for you considering your deadline?

#

If it is fair but if theres bigger tasks for your deadline than reducing the ram might be worth considering

hybrid tundra
#

as you could see

#

anyway, don't want to spam the channel

untold moth
# hybrid tundra as you could see

I can't see. I only have seen that you had a misunderstanding about a very basic thing. I didn't see any effort trying to read the info in the profiler or track the root cause.

dusty wigeon
#

You should really look into addressable duplicated. It has the potentially to save you from a shit load ton of memory with minimal work.

hybrid tundra
#

but seemed pretty complex

dusty wigeon
exotic trout
untold moth
# hybrid tundra

I must correct what I've said about this code. I didn't notice that you're accessing info.particles. I thought you were setting info = null.
However, if info type is a struct, then what I said is still correct to a degree and that wouldn't get rid of the reference.

echo coral
hybrid tundra
hybrid tundra
#

the things I mentioned starting with "fx_"

#

those are gameplay related

#

and I was in main menu, when I made the memory profiler snapshots

#

this is why I wanted to just purge somehow out of the references from FX script to at least see those disappaering from the memory profiler

#

but they're not

echo coral
#

If you say spawn a particle system in your gameplay scene and release it correctly (via addressables) when going back to the main menu scene, the textures will be unloaded for you.

exotic trout
#

dumb question but i don't think you've shown the particlesystemrenderers in inspector yet, that material isn't assigned to ParticleSystemRenderer's .trailMaterial right? you destroyed .material and .sharedMaterial previously and should maybe be destroying the renderers regardless but figured worth asking

echo coral
#

If Resources unload un used is called and this particle system game object was destroyed then we should presume it would have its textures be unloaded right? (Unless asset bundle assets and therefore addressable assets are excluded from this process)

#

my point being if this still does not unload the textures the solution is correct releasing or destroying all textures manually and praying its fine

hybrid tundra
hybrid tundra
#

because there are a lot of materials referenced by FX

#

getting rid of them probably won't unload the textures, but at least I wouldn't see those million references coming from FX appearing in Memory Profiler

hybrid tundra
#

the FX class still refers to the ParticleSystemRenderers holding the materials

#

I can't find anything else to set to null there

#

literally nothing

#

its unbelievable

echo coral
#

if you destroy the particle system game object it should solve the problem? Its not like this is going to work properly after your current adjustments

hybrid tundra
#

that's there in the Hierarchy during gameplay

#

but when I return to main menu, it disappears

echo coral
#

then some dangling references are preventing the components from being GC'd

hybrid tundra
#

well, currently

#

I have tried this

#

and even this didn't clean up all assetbundles, just to see if that would solve the issue

#

(I know it wouldn't be a final solution, I just wanted to see if this would get rid of references)

#

but even this was not effective

echo coral
#

c# objects leaking is not related to addressable asset releasing

#

you can correctly unload assets but keeping references to the c# objects will mean they dont get GC'd

hybrid tundra
#

I know, I just have zero idea how to track all references of the multiple hundred textures

#

if 1-2 texture releasing also takes for hours

#

its an extremely huge codebase

#

1-2 script have multiple thousand lines of code

#

so I really hope I find 1 solution which solves at least half of the memory issues

#

otherwise I won't be able to finish this optimization in time

#

I'm pretty sure about it

echo coral
#

to unload a texture just grab them from the materials and Destroy()
It will break shit later as things will presume the texture is loaded still but it will half solve the issue

hybrid tundra
#

what do you mean by "grab them from the materials"

echo coral
#

Your previous messages imply the textures are used mostly by particle systems?

hybrid tundra
echo coral
#

you want to destroy the Texture2D objects too

#

again, this will cause problems later

hybrid tundra
#

if there's a one line solution to destroy Texture2D objects, I will add it

echo coral
#

Destroy(material.mainTexture)

hybrid tundra
#

well, materials are on everything, maybe some of them are assigned from script, some are not, infinite amount of prefabs are in front of me

#

so this one line would be needed to add to million scripts

#

infinite amount of work would be to solve this

echo coral
#

If say you did this to spawn them, it would be easy to release them all too:

private async UniTask LoadPrefab()
{
    particleSystemPrefab = await Addressables.LoadAssetAsync<GameObject>("CoolParticle");

    for (int i = 0; i < 5; i++)
    {
        Instantiate(particleSystemPrefab, transform);
    }
}

private void OnDestroy()
{
    Addressables.Release(particleSystemPrefab);
    particleSystemPrefab = null;
}
hybrid tundra
#

I've counted with the Asset window, there's 4400 Mono scripts

#

in this project

#

nope, that's just one little script

#

which spawns some of them

scenic forge
#

There's no magic bullet to memory management, if your existing code has no care in the world about using and instantiating resources, then you are kind of screwed as you have discovered.

hybrid tundra
#

but that's all get released

#

problem is the million other scripts, which don't manage releasing well

echo coral
#

My example works easily because addressables only needs the prefab to be released for things to get unloaded

hybrid tundra
#

because in 1 month, I won't be able to track down all 4400 scripts

echo coral
#

that sucks but it wont magically work because you need it too

#

Perhaps you need to re read how addressable loading/releasing works incase you can infact correct things with less effort

hybrid tundra
#

honestly I'm thinking of asking someone to get assigned to help in the next month, and maybe 2 of us could reduce 5% of leaking

#

in 1 month

#

no idea

#

when I see that 1 material is referenced from 16 different places, scripts, Particle Systems, etc.

#

and that's just 1 material

#

and that's a long line of references

#

because that can go even further

echo coral
#

when talking about addressable assets, what the memory profiler says does not matter

hybrid tundra
#

well, if this can't forcely release all of these, I'm not even sure if everything is held by addressables

echo coral
#

As shown in my example, if we load 1 thing, we just release that 1 thing and it will handle the dependency unloading correctly
#archived-code-advanced message

hybrid tundra
#

I called this

#

and still it didn't clear up nothing

echo coral
#

Okay do you use LoadAssetAsync() to load prefabs? Or do you use InstantiateAsync() ?

hybrid tundra
#

LoadAssetAsync, InstantiateAsync, there are even Utils classes to do these, multiple one, I have counted last week like at least 40 different scripts which are loading addressables in some way

#

and some of them are monobehaviors, some of them are not

#

I don't know which one needs to release assets in which moment

#

or in which method

#

so its not that easy

#

if everything would have been in 1-2 scripts, then yeah, it would be very easy

echo coral
#

Then that spaghetti needs to be removed to simplify things so you can actually release things properly

hybrid tundra
#

this is why I'm panicking

echo coral
#

You can get all references to these functions and start reducing or refactoring

hybrid tundra
#

there are textures even from different games in the memory, because of its an inherited code

#

or legacy code