#archived-code-advanced
1 messages · Page 130 of 1
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
30-40% is not too bad for textures.
~200 textures left in the memory after I unload the complete level
well, based on memory profiler, the textures are the issue
and nothing else
Then they should be 100%, no?
Or I don't know. How do you define if it's a problem or not.
well, its the most huge part of the memory
that's how I define its a problem
So you have 60-70% occupied by many-many different things?
so, if scene unloading is not freeing up memory from textures, then what?
ignore that part pls
I wrote percentage wrongly
lets focus on textures left in memory
It depends on what textures these are. If they are used by the objects in the scene(and loaded with them), then they should unload together.
iirc TMP just uses Resources.Load internally, maybe UnloadUnusedAssets is what you need?
well, they aren1
*aren't
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?
game has 6gb memory usage
4gb is texture memory
what I see is that they stay referenced in materials
Are we talking RAM, VRAM? Or is it unified memory platform?
Then the materials are still loaded
no idea, Memory Profiler only tells its memory
how could those be still loaded after I unloaded the whole scene?
For example if you're instantiating them at runtime.
It makes a distinction between graphics memory and.. not graphics memory
Are you using the memory module in the regular profiler or something?
How are you even trying to optimize memory without knowing if it's RAM or VRAM? lol
If it's mobile or other integrated graphics it doesn't really matter
But yeah use the actual memory profiler
Investigate the chain of references. The issue is likely the objects that hold the reference to these textures.
Xbox Series S haunts me 
nope
why is that matter? game is crashing, most of memory is used by textures
and textures are leaking
it writes me gameobject names which are not even loaded at that point
at least Hierarchy window doesn't show them at all
Well, then they are loaded. You'll need to investigate these objects.
There's not much else we can tell you unless you share the info that you're seeing.🤷♂️
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.
TMP textures often remain loaded always (especially if used in the global fallback list)
If it's really what's happening, it's easy to confirm in the profiler.
Are you using additive loading?
yeah, that part is pretty unusable
no, they are not
at least not in the Hierarchy
Memory Profiler shows me textures which are pointing to gameobjects, which are not existing in Hierarchy at all
The hierarchy is not your whole game memory you know.
I know, but then where are these gameobjects
Unused assets aren't unloaded until you tell them to
https://docs.unity3d.com/6000.1/Documentation/ScriptReference/Resources.UnloadUnusedAssets.html
- Are you profiling a build?
- What are these gameobjects? How are they loaded? What does the memory profile show you when you select them?
- Are you gonna share more info or not?
- no, but the result was the same with builds
- 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"
In editor, you'll see a lot more assets loaded in memory. Things that you opened previously in the inspector, for example. This is very unreliable. Don't profile in the editor.
- I'm still investigating, and I'm also under NDA
As long as objects are in memory(not collected by GC), they are not null. And if they are referenced by something, they can't be collected by te GC. You'll need to look at what's referencing them.
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?
I know these
but I also know gameobjects like those are theoretically cleared up already
Profile the build
And see what's referencing them. Or if they are marked as don't destroy
assetbundle
that's referencing a gameobject which not existing theoretically at that time in the build
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?
don't know the project yet, I thought these are not active, when addressables are active
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.
addressables uses asset bundles, it's the same system underneath
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
can you help me find that?
the reference count thing
this one!
the addressable assets window is totally empty
during profiling
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"
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
it says Build report not found. Build report data is required to display correct frame data
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?
what do I need to browse here?
Those are the same rotation
turn this on in the addressables preferences and look for the file in your addressables folder (in Library)
you can enable build reports in preferences or it may ask you when you go to build bundles (2022 and later)
that was enabled for me
but how is that file called?
it will find it itself but it should match the build you are profiling (if in editor should be fine if done recently)
this should probably move to #📦┃addressables
not sure if you can easily find that if you make builds for NDA platforms
it will make the report when built for any platform
i'm pretty sure it always goes into Library\com.unity.addressables no matter what
you just need to add it to your reports window for use:
idk maybe, but these values should be absolutely the same, which they are not.
Otherwise this mystery happens
(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
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
Then either of those objects are wrong
thanks i ended up looking elsewhere in my code and found the issue!
after setting the orientation, i set the transform.rotation which is a parent of orientation, which caused these strange issues!
anyone have a clue on why the second ReleaseMutex() onwards throw a not owned error?
we're supposed to guess this without seeing any code?
im hoping this is a known bug but here is the code
There are no known bugs in System.Threading.Mutex no
I can't debug inside Mutex since it uses external code
ye i just cant put my finger on it
u can see from the screenshot i even log every wait & release event
maybe there's more than one WinRecognizer in action?
considering changing to named pipe IPC instead of shared memory IPC
i only called it once at the start and close it onAppEnd but will check anw
Trying to make my procedural spider walk on 90 degree surfaces, but it gets stuck on them sometimes.
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?
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
well one glaring issue is that you're feeding a world position into a method that is looking for a direction
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?
can the AsyncOperationHandles cause a memory leak, if I use Addressables.LoadAssetAsync and storing the handles only in local variables?
the handle itself is a struct, so it can't leak on its own, but you can use it in a way that causes a leak, likely pretty much everything else too.
well, if I just create them as local variables and not calling Release on them, then it will leak, right?
as long as it doesn't place itself or another resource in a scope that is not finalized when your local variable goes out of scope, then it wont leak
typically such types would implement IDisposable
can you rewrite this sentence with more simple words?
thanks
AsyncOperationHandles don't implement IDisposable but still need to be released
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.
The editor itself looks pretty minimal.
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.
Mine slowly increases to 50GB or so where it runs out of swap space and crashes
But yeah this doesn’t look like a lot
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.
and that's what is happening
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
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;
}
Your unity process eats 50gb at worst? Damn! Do you think it's because we have higher amounts of memory to begin with?
What I was really concerned with is, at some point my designer is going to end up in the engine, and if he doesn't have more than 16gb of memory, 10gb is going to destroy him
Thanks for the help breaking it all down
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
Has anyone used Arch (https://github.com/genaray/Arch/tree/master) with Unity? if so, how was working with it?
The downside I see here is that you still end up with GameObjects for basically anything... This is probably better in another engine.
Nah, there's plenty of shit you can do without GameObjects
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
do someone know how to use memory profiler?
if a gameobject has a Renderer, and that gameobject's own class holds a reference to it and its being stored, etc. But the gameobject gets destroyed once
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?
Unity doesn't release loaded assets until Resources.UnloadUnusedAssets is called.
ineffective
Are you profiling a build or the editor?
build
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
If you use addressable you need to release the handle
I know
If you use addressable, memory wont be release as long as another object in the bundle is still referenced.
also know
Memory profiler helps to find what textures are loaded and also helps you find leaked "managed shell objects". A texture can get unloaded from native memory + gpu but the c# Texture2D object can sometimes hang around longer (because only the gc can delete it).
more info: https://docs.unity3d.com/Packages/com.unity.memoryprofiler@1.1/manual/managed-shell-objects.html
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.
Resources unload won't help with addressable loaded things. Releasing loaded assets correctly is the real solution.
If object a is loaded and depends on texture b, releasing a will then unload b if nothing else needs b.
The only manual solution is to manually destroy the textures used by materials but this may break things later.
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
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
I will, but I'm so tired to censor all images
only tomorrow
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
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
You can use a dependency viewer package to help find what uses a texture
E.g. https://github.com/yassy0413/UnityAssetDependencyViewer
There are editor functions to get asset dependencies too
Sometimes an asset you didnt think depended on something infact does (prefab variants have some weirdness with deps)
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 ?
nevermind I found out
sorry sorry
#🎥┃cinemachine for the future
@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.
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).
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.
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
Click a group and change "Bundle Naming Mode" to adjust how the bundles a group makes are named:
https://docs.unity3d.com/Packages/com.unity.addressables@2.0/manual/ContentPackingAndLoadingSchema.html#advanced-options
"Those "leaking" materials depend on textures surely?"
what do you mean?
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
based on Addressable Assets Profiler, only those 7 materials.
based on Memory Profiler, its a lot more, like 500 textures
who to trust? I don't know
but Addressable Assets Profiler is experimental profiler module, so maybe I can trust more in Memory Profiler?
TRUST BOTH
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
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
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
look figure it out yourself ive said enough
ive said all i want to and i cant help any more
don't really understand why are you pissed off, but ok
1 material, 10 textures... main menu materials don't contain gameplay textures in this project.
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
Is 150 lines for an infinite layers recursive process good?
Nobody knows
Real
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) 
(here the camera stay & rotate at the side of thoses targets)
have you looked into target groups?
the freelook camera has a targetgroup as a tracking target, so it work fine
it's just that I want to preserve the current orbit when targets move around
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?
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);
Forget about addressables for a moment. Reproduce the state of objects being in memory whenever they shouldn't be, then dig into the reference hierarchy and check the info of each item. Ultimately, the deepest element in the hierarchy is the culprit. The info should tell you why this object is loaded, so focus on investigating that cause.
I would love to reproduce the state in an example project, if I would understand the reference hierarchy
can you check the page 4?
Select each object in the hierarchy and look at it's info. Especially the deepest gameobject.
Okay, and what to check for?
in the info
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).
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.
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?
from this FXCollection I can't go further.
Then maybe try double clicking it or finding it in the memory profiler and selecting it there.
you mean in the center, in the Unity Objects area, right?
Yes.
Same with this object. The Help basically tells you what's going on. You need to find what's referencing it.
I know that part, but where should I find what's referencing it?
is it visible from these screenshots?
can you see it?
No. As it's the deepest in the hierarchy. Find it in the unity objects area and look at it's references.
ahh, so I should do it back and forth between the Unity Objects tab and the References?
Yes.
good to know, it was not trivial
I can't find the ProcGenManager between the Unity Objects
so I guess that's the one referencing it?
It's in the reference chain for sure. However the profiler says that it is referenced once by something.
ahh, because of the Referenced By: 1, right?
I usually have very hard time understanding manuals, because they use very complex and long sentences
I usually just use youtube tutorials or anything else other than Unity manuals
Well, if you're asking in this channel, you're expected to have done a minimal amount of research on the topic.
I mean I know English, but maybe not that much, like someone native speaker
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.
I've seen some, but that didn't explain this part to me
okay
so to understand you correctly, if the Memory Profiler search field doesn't give results back for ProcGenManager class, then I should check the class itself, and especially that Dictionary the screenshot I've sent to you, mentioned?
What dictionary?🤔
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.
isn't it about the ProcGenManager contains a dictionary with TileConfig, which contains the RitualTileData, which contains NetOjectController, which contains the FXCollection, which contains List<FX>? I have seen that from other textures that the FX is on gameobjects, which have ParticleSystemRenderer, and that contains materials, which seem to be still in memory somehow
ProcGenManager is referenced in 84 places in the entire project
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.
and can't I write something into the ProcGenManager itself to release its own stuff?
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?
I'm not sure if OnDestroy is called before the GC collects it, but if it does, then theoretically nulling all of it's fields in OnDestroy should work. But I'd rather make sure the ProcGenManager is not referenced after being destroyed instead.
It's referenced in a script somewhere. Like a DDOL or there's a static reference to it.
I mean it will be just painful to check all 84 places where ProcGenManager is referenced
and even if I modify all 84 places
then still that won't be 100% sure to get a meaningful result in the memory
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.
I mean I have clicked in Visual Studio right click onto the ProcGenManager name, -> Find all references
and it gave me 71
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.
but Unity itself wrote 84 references above the ProcGenManager class header
What header? Are you doing C++ or something?
Well, that's what I'm telling you - be smart about how you look at the references.
noo, not header, class declaration I meant
in here it writes 84
oh okay
from your image now I get it
Again, it's all the places it's refrenced. Not all of them are relevant
I've checked it. So I can only see these:
in million places: ProcGenManager.Instance. <- and its refering to the fields of the class
ProcGenManager.FromMenuSeed
ProcGenManager.TileSize
ProcGenManager.TravelPointData data = ...
there's only one place, where I can see
static ProcGenManager _instance,
but its in the ProcGenManager itself
maybe _instance should be destroyed, when returning to main menu
right?
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.
yeah, probably who wrote it also wanted it to make it as a singleton
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?
It depends. Some engine features might be requiring them on the CPU side.
Try disabling them and see if anything breaks or errors are thrown.
hmm, then maybe I should ask the others if those were setted intentionally, because it would take infinite time to test each part of a multiple hour long game
Yeah. It's always good to ask whoever is responsible for it of their intention.
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?
I think it's off by default
:/
so I can be happy, because there are cases apparently, when its enabled by default
and then I could disable it
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
is rigidbody added to the laser go?
nono
then add it 🙂
Hey anyone free for a call today? I've got something really interesting
Pretty sus, considering you just joined the unity discord today
these channels aren't for private help regardless.
Not trying to be sus and I don't need help!
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.
You should just post it here
Not what im looking to do that this stage. Looking for a one on one conversation. I know that asks alot, im sure lots of social anxiety here.
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.
Procedural logic = loops and conditionals.
Just post your question. Nobody is going to ridicule you
I don't have a question! I am trying to TALK to someone about my system. Not type. I want someone to feel the weight of what im saying. I am simply looking for someone who wants to understand something new.
👨🏿
you are incredibly unlikely to find someone here willing to talk with you one on one about something you are being incredibly vague about. either describe this "system" here or find somewhere else to ask for private conversations at
Thats fine. No who im looking for then. When I say "eliminate loops and conditionals" the right person will want to speak with me. That person may not be here and that's fine.
That person probably is here, you're just choosing to be difficult.
I can't speak for anyone else, but for me it just sounds like you have no idea what you're talking about
Nobody wants to hop in a call with a random person. Especially people that do know their shit.
I apologize if I come off that, purely want a conversion with someone.
Good luck
Thanks!
then have the conversation here in this channel. this server is not the place to seek private one on one conversations/help as the pretty much completely defeats the purpose of a community server.
Thats cool brother, that's what the conversation is for. Have a good one
Noted. Looks as if I am in the wrong place. Thanks
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.
intentionally being vague about this and refusing to elaborate publicly is going to pretty much guarantee nobody wants to discuss it with you
All good, im in the wrong spot. Take care
lmao
Is there actually a point to this or did you just want to show everyone you just learned about declarative programming
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
Sounds like something a complete beginner might be interested in. Maybe try in #💻┃code-beginner
Join the Discord ► https://discord.gg/PPX5qcq
Patreon ► https://www.patreon.com/nimsostudios
Twitter ► https://twitter.com/nimsoStudios
Itch.io ► https://nimsostudios.itch.io/
#vr #virtualreality #locomotion #vrgaming #vrchat #virtualrealitygame
The Hybrid Presence Engine now has INTERACTIONS EVERYWHERE!
We've got sounds, sharp & point...
you have to at least give people an idea of what it is you actually created
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
They're not even still here, they left a while ago
shucks
I was going to ask what the motivation for eliminating conditionals is
what could possibly be a better solution than if(a < b) { ... }
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
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.
There seems to be a bug in Unity's render pipeline where floor of negative 0 becomes -1 instead of 0. I think.
the floor of -0.5 is -1
not -0.5. Floor of -0
same
https://en.wikipedia.org/wiki/Signed_zero
it's not the 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
its only a bug if what you see is different from what the language/API spec says that it should be. wikipedia has no authority over unity or C#
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?
can you show the code that exhibits this behaviour?
i would assume that unity follows IEEE 754 and does its own thing only in edge cases where IEEE doesn't specify a behaviour, if you are talking about math or mathF libraries those should match the specifcation of hlsl.
I'm pretty sure C#'s float doesn't have signed zeroes
What context are you running into this from?
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
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).
are you making sure that your 0 is actually 0 and not 0 - float.epsilon?
Unity shaders are just run through whichever graphics library you are using, like DirectX 11 or Vulkan. Unity doesn't implement the floor function or float operations in shaders, so this cannot be a Unity issue.
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.
I actually want floor(0)==0. However unexpectedly, sometimes it has -0 for the same pixel, and this seems to result in floor(-0)==-1
Did you actually check it with some kind of shader debugger?
I really doubt a signed zero is gonna appear somewhere naturally without you explicitly using it.
I'm surprised that the pixels change values even while the game is paused. So unity is doing something unexpected
by "game is paused" do you mean "Time.timeScale == 0"? Because that doesn't affect everything 🙂
Paused how? If it's still rendering every frame, floating error is very much possible.
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
Well, that doesn't stop rendering.
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
Every time a shader executes it can get a different value due to a floating point error.
Not necessarily.
If that was true, z fighting wouldn't exist
as I understand it you never get -0 unless you explicitly use it
Anyways, you'll find all the answers if you just debug your shader.
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.
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
Again, if you're concerned, you should debug the shader. Perhaps there's an underlying issue that could lead to other problems.
I have never debugged a shader at this level of detail. What would you suggest?
On windows PIX or probably Nvidia Nsight(or one of the related tools). AMD has a tool as well I think. Other platforms have other tools. For me PIX is the most straightforward, though it might need you to use d3d12 as graphics API.
You can debug it almost as any other code(with some shader and GPU peculiarities) - you can see the exact values of the variables at each step.
You'll probably need to research how to output the shader debug symbols in unity.
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.
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).
make it work with absolute values only, later add the sign based on input values. 1/3 is not an irrational number in float representation. 1.0/3.0 ~ = 0.33333334f but i don't se how that matters here unless you add these up and try to get to 1... where you could again do some rounding.
How can I make the rotation of the procedural spider to be more natural? I'm currently using Quaternion.RotateTowards for the rotations. There's alsoa bug where the spider rotates inside a wall when the horizontal ray collides with a wall.
{
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;
}```
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...
What files is it complaining about?
Making a build is the same regardless of how you downloaded the project.
I followed this idea, and came up with
int temp = (pY + resolution * 10) / int(resolution)-10;
This feels like a very strange way of doing things, but it avoids the issues relating to the floor function with floating point discrepancies
10 resolution widths is well outside the visible screen, so I guess it's "fixed" now.
Assets/StreamingAssets/addressable_keys.json
The problem is floor(int(3)/float(3)) sometimes results in 1 and sometimes 0, due to whether it feels like being 0.3333333f or 0.33333334f. I still don't know why the Unity renderer is not consistent about which one it is.
What about that file?
Are you seeing a specific error related to it? When and where do you see the error and what does it say?
Version Control: Cannot check out files in offline mode
Assets/StreamingAssets/addressable_keys.json
UnityEngine.StackTraceUtility:ExtractStackTrace ()
You're in offline mode apparently
I am
Well that would certainly explain why it says you're in offline mode
it was never a question that I'm in offline mode
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
well, I can only be online, when I actually work in the workplace
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
? everything is downloaded for build
its Perforce
this keys file gets generated in this way: PreBuildJSON:OnPreprocessBuild
AddressableKeysTool:GenerateJSON ()
AddressableKeysTool:Export ()
so its not something which is missing
That sounds like a Unity Version Error, no?
This
Are you using the Provider API in those scripts?
I don't know what is the Provider API, I didn't wrote those stuff
Well maybe whoever wrote those scripts should be debugging them, or you should ask them for help debugging them.
well, those scripts have no problems other than that these make issues when its used away from Perforce server
Yeah and?
My car doesn't have problems unless I drive it in the swamp.
How do you calculate py? What makes you think it's the unity renderer?
It only depends on the UV coordinate sent by the renderer, and the Resolution which is constant
Is pv == uvs?
It would have nothing to do with the unity renderer. The uvs would be constant on the CPU side, on the GPU they pass through the vertex shader and get interpolated to each pixel. This has absolutely nothing to do with unity and is a quirk of the rendering process on the GPU.
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.
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.
Is it actually 33? An integer? Is the type an integer? Why did you mention 0.3333 before then?
And I'm telling you that you can solve that problem by adding half the pixel width. This would not be enough to shift to the next pixel, but enough to offset any floating point error.
Adding half pixel size in this kind of scenarios is a very common practice in shader code.
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
not 0.5. Please don't distort my words. Half of the pixel resolution.
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.
float pYMid = pY + (0.5 / resolution);
int temp = floor(pYMid / float(resolution));
resolution in this case is the cell resolution, rather than the screen size. The Hex resolution is about 198x66
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.
This solution seems to also work
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.
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)
It's very nearly identical, however adding 0.5 of the width is 1 instruction less. I think it's cleaner, I will use that.
Also big thanks goes to Red Blob Games for their great guide on hex shaders.
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.
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???
I have checked that, but it didn't solve the optimization issues at all, unfortunately
the same textures are leaking
Ondestroy: if not null, object.remove
I forget the exact function calls
If you don't, then you will leak GPU memory
Usually its Dispose or Release
one of them is a call to the other
check the source its on the C# side
but this is what I wrote
Then repeat the investigation. Does the manager still leak? If not, then there must be other issues.
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.
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?
its still leaking
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
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?
so going back to sleep
its 99% gets called, because the manager gets destroyed
when going back to main menu
This is an assumption. Place a breakpoint in the code and confirm with a debugger.
okay, I will check tomorrow
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
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
!collab 👇
: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
make a game wit me
that's literally collaboration
it literally did until you edited it. and even still, it currently says "make a game for me" which is still a collaboration request. take it to the discussions site like the rules state.
yeah yeah save it for the judge
thx for this tho
I have confirmed it, ProcGenManager's instance gets setted to null
@untold moth maybe this one particular thing was solved, seems to be missing from the current references
Then continue investigating. Check the next last thing in the reference chain.
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
It has something that references it. Don't you see that there's something deeper in the hierarchy?
that was referenced from SaveDataManager, but that can't be cleared up, because that's existing in DontDestroyOnLoad
I think only the MultiplayerGame is the point where I can do something
If it's referenced in SaveDataManager then it needs to be cleared up if you want to clear it up, no?
well, SaveDataManager is existing all the time. And it should exist all the time
I still don't really get it then
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?
I mean its referenced from SaveDataManager, but that should be referenced from there I think (not sure)
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
but if its referenced in savedatamanager, it should be in memory and therefor shouldn't be cleaned up?
MultiplayerGame itself could stay referenced by SaveDataManager, because that doesn't contain anything else related to textures, only TileConfig
I mean MultiplayerGame itself is just a script, its not a texture
if its referenced, I don't think its a problem
or I still don't understand some basic stuff
Late to this convo, how much memory is this object using? is it worth fixing this?
not much, but there are 7500+ textures in the project, and lot of them are stays in the memory after gameplay
(heads up that you have been in this convo before :P)
If its just the c# objects its not that big of a deal
the hugest textures are japanese and chinese font atlases
but those are not leaking
those are just huge textures constantly inside the game
tmp?
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)
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
I just mean 2.40 gb is incredibly much more than it should be
and its causing issues
If you want to cut the reference chain at the TileConfig, then you need to make sure it's not references anywhere else. Is it only referenced in the MultiplayerManager? What reference count does the profiler show for it?
yeah
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
Ok, so did you profile after setting it to null?
yeah
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?
And what's coming up in the hierarchy below it?
so MultiplayerGame has reference to TileConfig. TileConfig references to RitualTileData. That refers to NetObjectController, that goes to FXCollection and that goes to List<FX>
MultiplayerGame itself is referenced by 9
Ok, then you need to set it to null in MultiplayerGame.
already did that
MainTileConfig = null
and Resource.UnloadUnusetAssets()
Then it didn't get set to null. At least not entirely.
inside OnDestroy
(or one instance that remains during the menu?)
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.
its inside a material
so should I rather modify FX class?
if you do new Material() you need to destroy those material instances too manually
nope
otherwise UnloadUnused should suffice for unity managed material instances
Addressables is different but I dont know if this applies here 🤔
Maybe it's fine to delete these scripts? Considering they're in "unused" folder.
They're trying to get rid of the managed objects. These wouldn't get unloaded, since they're referenced.
Might be worth confirming this is running (and on all the ones that exist?)
and this is a seperate issue to their "texture" issue?
The textures are referenced by managed objects.
so only the "managed shell" is leaking?
I'll Comment the code inside the file.
I don't remember. I think some objects in the chain are not even destroyed due to being referenced by shell objects.
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
its not living there
I can see it disappearing from Hierarchy
when returning to main menu
did it move to another?
Aha I wasn't aware that UnloadUnusedAssets() examines managed objects so this does matter. TIL 💡
based on my understanding of unity, you have said something wrong
Hierarchy is not everything...
it either called ondestroy or it exists somewhere
but they saw it leave the hierarchy
Assets don't appear in the hierarchy
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?
Perhaps it was never in the hierarchy in the first place. Hard to say for sure without more context
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
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
Is it an exception/error?
And btw, I don't think it's wise to call unload unused assets in OnDestroy
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
yeap
attempting to use an invalid operation handle
because I call base.OnDestroy
It depends if we're talking about managed or native side. I think native might be released separately.
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)
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.
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)
okay, that reference disappeared
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
Check the profiler. They're either referenced by something or set to ddol.
why its still not enough to get rid of the FX reference?
Because you need to read what the profiler is telling you...
so it seems to be that I still don't understand the profiler?
what the profiler says?
Didn't we go over these many times by now?
Start by reading the details/info below the hierarchy
I don't get it... M_fx_ParticleSet_01_apb is a material. Its referenced by 9.
Checking those 9, these are 9 particlesystemrenderers...
those are ALL coming from 1 single place, which is the FX script.
what else should I see here?
(also just because it was relevant last time, did you confirm this code is running?)
yes, its running
because I have tested modifying this script weeks ago
this was the first thing I did
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)
if it would be running, then I would not have wasted literally entire weeks to solve this issue
I'm panicking, I'm stressful, I just want to finish this
honestly I don't even know what else should I do
I'm running out of ideas
you could try destroying the materials before setting them to null
ok, I will try that as well
If they are coming from the script, they are referenced in one of it's fields
that's pretty obvious btw
And I don't see you setting these fields to null anywhere
you think that I try to solve stuff which is pretty obvious
but this issue is not obvious at all
@untold moth
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
None of this code sets fields to null...
there are fields which I don't use there, yeah, but why would I need those in here?
Looking at the hierarchy, there seems to be an array of renderers.
@untold moth those ParticleSystemRenderers are exactly the same (receiving from GetComponent) which are already cached in the script
No it's not. You're just creating a new array when you get components.
There is an array field that holds a reference to these.
but I'm manipulating the exact same ParticleSystemRenderers
That's not the point though
there is, yeah
The point is that they can't get collected by the GC, while still referenced
so if two different variable refers to the same component, and only one of them sets stored material to null, then it won't get cleaned?
But i don't think he's trying to destroy the particle systems, just detatch the asset from the systems?
Texture usually does not needs to be collected by the GC to be freed because they are Graphics object. They needs to be released.
No. And not just a variable, but a class/struct field.
I give back my degree
Why?
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?
is it better?
now its a field
(but I'm still referring to the exact same components)
No. You need to do array[I] = null obviously
but he's not trying to clear that?
I mean, local fields count as well, but they don't live outside their scope.
The GC won't collect the managed objects while they're still referenced.
why is that better than this?
You might want to try #archived-code-general
its pretty advanced topic
Because all you do is assign null to a local variable.
not really trivial
You are flooding the channel
Yeah I thought he was trying to clear out the textures and materials no? he's not trying to get the particlesystems cleaned up
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
Not sure in which situation you would want to keep a particle system with no material assigned.
I mean sure but that's not why dlich wanted to ensure they would be destroyed
Textures are also linked to managed objects. I'm not entirely sure what's going on there, but for now it's clear that they're being part of a reference chain.
Anyways, looking at the profiler details would reveal more.
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 😄
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
I mean, this is basic level programming. Asigning a reference to a local variable is not gonna change the value of a field
pretty advanced though
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
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#
dlich what reference did you want tamas to try and clear/unreference/destroy?
value of what?
the on'es in the array
the particlesystemrenderers right
what value is a gonna have?
Yep.
Tamas are you aware dlich is suggesting you destroy the particlesystemrenderers themselves and not the values inside of them
The same happend in your code
Reference would behave the same way
well, material and texture seems reference types
this is why I didn't understand
The same behavior is true with refereneces
private MonoBehaviour a;//assigned somewhere else, not null
void Method()
{
MonoBehaviour b = a;
b = null;
}
same question
then a is also null
after the method
no
I would be surprised
Then try it out
Try it out:
https://dotnetfiddle.net/cTIWGZ
See what the console prints
aren't references memory addresses?
or pointing to memory addresses?
if I create a List<int>
and I give that to a function
Sort of. But that doesn't change how asignment works.
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
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.
You're mixing up different concepts here.
When you change values in a list, you modify the contents of the list, not the reference to the list.
but I refer to the same list
the method's local variable gets assigned by the variable outside
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.
same with List<int> a=b;
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.
@untold moth so to understand, should I set ALL particlesystem references to null in the FX script?
All the class(or struct if you have) fields, yes.
I'm too dumb for this task apparently, because its still can be seen in Memory Profiler
Read the profiler data. Compare to before. Do you see a decrease in references count? What other metrics are saying? Read it all.
I don't even understand why there are 3 different "Referenced by" window for the same texture
3 different windows?🤔 Not sure what you mean.
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
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.
Yeah, these are 3 separate objects in memory.
You can even see that one of them has smaller memory footprint. Maybe a mip level or just a lower res texture?
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
They're usually at the top. But you can also view all the class members in visual studio(or some other ide).
I mean if it takes me 1+ week to maybe decrease 1-2 MB of memory and its still like 1 gb I would need to free up, this whole thing is not effective
I'm not effective in this task
until now I just wasted time with this
maybe I will see something in a test project
This is why you need to investigate properly and find the root cause. There's likely only a few lines of code or assets that are responsible for all of this.
yeah, I know FX class is responsible for a big chunk of memory
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
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).
You potentially have duplicated assets(due to asset bundles) if you are not expecting to have 3 of it.
I'm not expecting anything
I have expected to at least reduce the number of references, but so far I couldn't achieve it
Do you have multiple texture called T_fx_Particles_01 in the project ?
because apparently reference counts didn't even decrease
nope
Do you use Addressable
Reference counts of what?
yes
anything
honestly
this project has so much textures and references
Have you look at the Addressable Report
I would have been happy if I could have reduced at least a few
Did you not manage to remove the manager thing from memory yesterday?
I could remove that, but that was like 1 out of the 10 thousand references
or even more
ok, so the "I couldn't achieve it" is totally wrong.
I'm not happy with my own results, that's what I wanted to say
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
Then focus on understanding the issue. Blindly testing different things is just gonna be a waste of time.
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
yeah, the last 5-6 hours were very effective in understanding the issue
as you could see
anyway, don't want to spam the channel
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.
You should really look into addressable duplicated. It has the potentially to save you from a shit load ton of memory with minimal work.
even for addressables I would need a test project, because I have worked with addressables million years ago, and don't really remember how they work
but seemed pretty complex
If you do a seperate project you would not know if you have an issue with duplicated in the current...
I mean yeah you are dealing with relatively complex stuff here
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.
Checking for duplicated assets is a good idea, you can use the built in analyser and fixes to quickly fix them:
Addressable build reports also show duplications so you can check that also and focus on duplicated textures (this would ensure it doesnt load duplicates of the same texture into GPU memory!)
not a struct, its a class, and I know a struct would be a value type
even if these textures are duplicated, that doesn't matter, because these should not exist at all at this point of the game
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
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.
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
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
the materials are in Renderer's Material field
currently I'm not trying to fully unload them, for now I just wanted to check if I could get rid of the FX reference
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
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
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
the parent gameobject gets destroyed
that's there in the Hierarchy during gameplay
but when I return to main menu, it disappears
then some dangling references are preventing the components from being GC'd
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
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
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
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
what do you mean by "grab them from the materials"
Your previous messages imply the textures are used mostly by particle systems?
there are some of them used by particle systems, like maybe a quarter of them, or even more. But I tried to call Destroy on them. I tried to clean up those materials like at least 4-5 way and it just can't die
if there's a one line solution to destroy Texture2D objects, I will add it
Destroy(material.mainTexture)
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
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;
}
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
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.
but that's all get released
problem is the million other scripts, which don't manage releasing well
then I will fail
My example works easily because addressables only needs the prefab to be released for things to get unloaded
because in 1 month, I won't be able to track down all 4400 scripts
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
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
when talking about addressable assets, what the memory profiler says does not matter
well, if this can't forcely release all of these, I'm not even sure if everything is held by addressables
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
Okay do you use LoadAssetAsync() to load prefabs? Or do you use InstantiateAsync() ?
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
Then that spaghetti needs to be removed to simplify things so you can actually release things properly
this is why I'm panicking
You can get all references to these functions and start reducing or refactoring