#archived-code-general
1 messages Β· Page 435 of 1
I mean that unity a bit fragile regarding configs in editor.
using a DI container to solve that is maybe a bit off the side.
it also doesn't solve it entirely, you loose all static code analysis regarding dependencies
may be u right, I don't have much expirience with Unity. And generally guides/tutorials doesn't go too deep on design. So try and error is a way for me at the moment.
There is a tool to check dependencies in Unity configured in editor?
what do you mean?
you can check for missing references.
I mean i see if I run program and I can check manually. Is there way to do it automatically?
maybe I'm misunderstanding smth
personally i think many ideas from DI are very valuable, i just don't like to have a framework dictate which ones we use in a project π
you can make an editor tool that checks for missing references, or get Odin Validator
what i like to do is make static editor references for everything thats part of a scene and use a service locator (basically a container) to lookup the managers/systems that any dynamically spawned objects belong to, register themselves with that manager and have that manager manually inject the dependencies OnRegister.
i find the ceremony that creates strikes a balance that it makes people think of how they want to organize their systems and offers sufficient resistance to "just inejct one more thing" while also making it easier to setup, debug and robust.
if you pair that with asmdefs for all primary systems and design your systems in a layered way, the project can partially self-guide a developer to a correct solution by offering a path of least resistance that we actually want to take.
yep, I tried to do it with asmdefs, but it's too much for me for now - i spent a lot of time on design, while not having enough expirience. as a result I had a lot of code to support design, but had very few fetaures) As of now I'm going with "go fo features" and "refactor when it's needed". Since I'm doing sorta pet project myself, it works for me. for bigger projects focourse it wont work)
But you right, I need to be more carefull with injections, since it becomes spagetti quite fast.
Is there a way to access the C# 10.0 file-scoped namespaces feature in Unity? Would like to make use of namespaces for my current project, but adding an extra layer of indentation is a bit aggravating.
no because unity uses an old version of mono
unity 6 is on C#9 feature wise but also is missing a few features
also namespace per file is more namespaces then i would want, and would not worry about 1 extra indentation level
i dont know if "don't worry about it" is a valid response to someone's problem lol
IIRC file scoped namespace is a compiler feature not a runtime feature, so you could get it to work in Unity by patching the compiler binary to a higher version
But eh, I wouldn't recommend it.
yeah, it can be a mistake to design too much when you don't actually see the actual problems yet, you end up with lots of clean systems that do nothing, but conform to all the buzzwords. I certainly did that for years. Its a problem to solve all in itself.
Hey folks! Have run into quite the doozy of a bug, and there's nothing online I can find to help.
We have one user who is experiencing a crash just after opening our program. The issue is a StackOverflow exception originating from the Cursor.SetCursor() function.
This works on thousands of other devices, so I assume it's something specific to the user's machine that's causing it. If anyone has any ideas on how to troubleshoot this one, it would be mighty appreciated.
Stack trace below:
StackOverflowException: The requested operation caused a stack overflow.
at (wrapper managed-to-native) Interop+Kernel32.DeleteFilePrivate(string)
at Interop+Kernel32.DeleteFile (System.String path) [0x00008] in <694551e795764b938030a3128fac2b36>:0
at System.IO.FileSystem.UnityDeleteFile (System.String path) [0x00000] in <694551e795764b938030a3128fac2b36>:0
at System.IO.FileSystem.DeleteFile (System.String fullPath) [0x00000] in <694551e795764b938030a3128fac2b36>:0
at System.IO.File.Delete (System.String path) [0x00014] in <694551e795764b938030a3128fac2b36>:0
at (wrapper managed-to-native) Interop+Kernel32.DeleteFilePrivate(string)
at Interop+Kernel32.DeleteFile (System.String path) [0x00008] in <694551e795764b938030a3128fac2b36>:0
at System.IO.FileSystem.UnityDeleteFile (System.String path) [0x00000] in <694551e795764b938030a3128fac2b36>:0
at System.IO.FileSystem.DeleteFile (System.String fullPath) [0x00000] in <694551e795764b938030a3128fac2b36>:0
at System.IO.File.Delete (System.String path) [0x00014] in <694551e795764b938030a3128fac2b36>:0
at (wrapper managed-to-native) Interop+Kernel32.DeleteFilePrivate(string)
at Interop+Kernel32.DeleteFile (System.String path) [0x00008] in <694551e795764b938030a3128fac2b36>:0
at System.IO.FileSystem.UnityDeleteFile (System.String path) [0x00000] in <694551e795764b938030a3128fac2b36>:0
at System.IO.FileSystem.DeleteFile (System.String fullPath) [0x00000] in <694551e795764b938030a3128fac2b36>:0
at System.IO.File.Delete (System.String path) [0x00014] in <694551e795764b938030a3128fac2b36>:0
at (wrapper managed-to-native) Interop+Kernel32.DeleteFilePrivate(string)
at Interop+Kernel32.DeleteFile (System.String path) [0x00008] in <694551e795764b938030a3128fac2b36>:0
at System.IO.FileSystem.UnityDeleteFile (System.String path) [0x00000] in <694551e795764b938030a3128fac2b36>:0
at System.IO.FileSystem.DeleteFile (System.String fullPath) [0x00000] in <694551e795764b938030a3128fac2b36>:0
at System.IO.File.Delete (System.String path) [0x00014] in <694551e795764b938030a3128fac2b36>:0
at (wrapper managed-to-native) UnityEngine.Cursor.SetCursor_Injected(UnityEngine.Texture2D,UnityEngine.Vector2&,UnityEngine.CursorMode)
at UnityEngine.Cursor.SetCursor (UnityEngine.Texture2D texture, UnityEngine.Vector2 hotspot, UnityEngine.CursorMode cursorMode) [0x00000] in <ac95ed96621641249c5b2cf74e341b4b>:0
at CursorManager.SetCursor (CursorManager+CursorHovering hoverMode) [0x00014] in <6e83f6c4bf5f4c66a3cb9e8f835d6063>:0
at CursorManager.Awake () [0x0003c] in <6e83f6c4bf5f4c66a3cb9e8f835d6063>:0
Certainly looks like a bug in System.IO.FileSystem.UnityDeleteFile
Perhaps isolated to whatever hardware or operating system version the user is on
Do you happen to have those details?
All I've got is that it's Windows 11. It's a very low-tech-skills user, so stepping them through the process of getting more detailed system specs will be a challenge
Why does FileSystem have a unity-specific class/method π€ (I don't really know how these things work)
I think IL2CPP implements a whole bunch of low level C# stuff in its own way
π§ββοΈ
Im not sure how it would go from kernal 32 back to File.Delete() π€
well you can view the il2cpp generated src from a build so that may reveal some info
It's a mighty weird one for sure.
It's a mono build. Would probably need to bust out a decompiler to view the source
oh mb i presumed il2cpp. You can use something like ilspy to view a nice decomp of the source to see what this function does
managed mono only, if this is a call to native engine code it wont help much
s'all good π Sounds like it may be the way to go.
where I work moved to enterprise so soon i get to view the unity source which sounds useful for stuff like this π§
It's been tempting to grab it. Worried about being locked to a specific version though. The ~20k price tag is a lot as well π
yea i know it can be expensive. hopefully you can figure it out without
Fingers crossed. Worst case, a refund for this extremely rare bug is cheaper
there a way to correct that tilt? thats the general camera perspective (static camera) and it's getting noticable tilting. Whats the correct math here? google-fu failing me. maybe its the shader i'm using (distance field)
(line 105 is where its facing the camera), dont think the rest is having any effect here but just in case
you want it to look not at the camera but at the nearest point on the camera's plane sounds like
So you could do this:
Transform camXform = Camera.main.transform;
Plane camPlane = new(camXform.forward, camXform.position);
Vector3 lookAtPosition = camPlane.ClosestPointOnPlane(tmp.transform.position);
Quaternion rotation = Quaternion.LookRotation(lookAtPosition - tmp.transform.position);
tmp.transform.rotation = rotation;```
I think it's just a function of having a perspective camera. It looks tilted because of the angle it's on
The tmp is set to orthographic
Lemme try that
Is it on a worldspace canvas?
but the camera is perspective
What you'll likely need to do is figure out the apparent rotation of the text in the axis from the camera to the text, then rotate the text around that axis so that it appears straight.
I'm about to head to bed, so I definitely don't have the mental space to figure that code out
Since it's facing the camera already, you're basically just creating a W axis along that Vector and rotating the text around it
ah yeah that does it. although its backwards
easy fix

Quaternion rotation = Quaternion.LookRotation(tmp.transform.position - lookAtPosition);
just had to reverse that line
Yeah since it's really the back of the TMP you need to see
Anyone have much experience with Unity Terrain & Trees? I have an open world which contains a very large amount of trees.
I'm adding "destroying" to the trees. But currently I have to map every tree on game load into a spatial map, then when a player tries to break a tree, do a lookup find the tree index ect.
Then when they actually break it, I have to swap out the prefab index, to a "hidden" tree (blank prefab effectively)
Then I have to swap collision on and off for it to recalculate my new prefabs collision (if i don't do this the old trees collision remains)
Is this a poor design choice? Should I be using game objects for trees, not terrain data. Then despawn them far from the client? (I have a server that I've mapped all terrain trees so that I can send tree information to the clients given they are close enough)
The other solution I thought of was a hybrid approach where I keep the trees on the terrain but disable collision, and spawn box colliders over the trees.
I'm finding some conflicting information from what i've read. Curious if anyone has ever dealt with this. Thanks!
IIRC Unity's terrain system is rather inefficient. Gameobjects with occlusion culling and LoD/fading out at distance with box colliders should be very performant
I'd probably go the gameobject route personally. Also gives the option for further functionality that the unity trees system can't provide
awesome, we will probably go that route then. And yeah that was kind of also what I was thinking, what if I wanted to add a tree falling animation. I'd have to like spawn a game object over the terrain data before i swap to the hidden prefab. Gets very messy
Thanks for the info!
Itβs inefficient memory wise and has a weird API, the problem is not its rendering/auto-lod within the constraints of that.
Oh uh. I thought it was the other way around. The terrain provides a brush to instance the trees while removing the overhead of using gameobjects
Makes sense to make them GOs if you are destroying them though, but then you need to compare batching all of them vs chunking
How can i stop a 2d object from rotating? When i change it's linear velocity it tends to rotate on the z axis, and when i set from code it's rotation to always be 0 it's twitching
Rigid body? You can lock the axis
hey yall, I have this script
using EnemyNun;
using UnityEngine;
namespace EnemyDummy {
public class DummyController : EnemyController<DummyController> {
public GameObject prefab; //respawn yourself when you die
public Idle idle;
public Death death;
private void Start() {
SetState(idle);
}
public override void OnDeath(HitData data)
{
base.OnDeath(data);
SetState(death);
Invoke("SpawnNew",1);
}
void SpawnNew() {
Instantiate(prefab);
}
}
}
and im having a weird issue. When a dummy dies I want it to respawn a new version of it. I have made a dummy prefab, set the prefab reference to that prefab, and placed one in the scene. However, when I run it, it immediately sets the prefab to itself, the scene instance, rather than the actual prefab. This is not what I want because then it spawns a glitched out dead prefab. Is this normal? is unity just being weird? Or is this some stupid thing where unity can't tell the difference between a prefab instance referencing the prefab and referencing itself
since the prefab DOES reference itself maybe its just like
assuming thats what the instance is doing
ive been directed to this https://discussions.unity.com/t/prefab-with-reference-to-itself/631334
Yeah Unity does like convert refs to self prefab assets to the instance of itself
unfortunately
the same way components on the prefab reference the instance
Ah I was replying in #π»βunity-talk about that. I completely forgot the reason that issue exists is because other components need to reference the spawned instance rather than the prefab's component
Makes sense but it's a real shame there isn't a solid, streamlined solution to it
I guess that makes sense, even if that behaviour on a gameobject is really pointless
idk how it would work but maybe a PrefabReference container or something would work
thats kinda hacky too idk
its not how it works but ideally would be great to just have some attribute we could use to mark stuff to not like transfer
oh an attribute would probably be best yeah
in your case, i dont know if you'd have an external object that could store the reference to the prefab. Maybe doing it through a scriptable object is simplest
imma make a dummy spawner script and hope I never need to solve this issue again
I usually use a "Definition"/ScriptableObject to spawn my objects.
I don't think it's a solution but in theory it is possible to iterate through the prefabs and compare object names but blahh
Which does not have the issue, you might want to use the same strategy here.
in the link that i sent (that willow resent in this channel), there are solutions that use like Resources to solve it. Its just definitely not what anyone would wanna do
I didn't mean resources
It helps in the event that you need to reference the "meta" object. I.E. the name, description or other settings that should live without an instance of a prefab.
iirc you can iterate through the scene objects in the hideanddontsave scene which will be the currently loaded prefabs in memory
string comparison still yucky but a abit more controlled since both comparison points are established during runtime yknow
π€·ββοΈ never really heard of that myself but either way that's still not what anyone would wanna do. just putting it in a scriptable object would be miles better
SO in a lot of cases is probably preferable yeah, But there's reasons I've found to at least be interest in that approach though
hi yall, I'm making a character controller but im having issues with the camera, this is what it looks like and this is the code, otherwise nothing really impacts the cam
https://cdn.discordapp.com/attachments/493511037421879316/1354981561967050896/2025-03-27_18-52-12.mp4?ex=67e7446a&is=67e5f2ea&hm=10776bccd5a522ad73258d787ed5e883e4a1d9e7e4a22f1b84a925de9cc8d4af&
The issue is NOT time.deltatime
https://unity.huh.how/mouse-input-and-deltatime it most certainly is part of the issue at least
also, use cinemachine and you dont need to make your own camera controller
Just stumbled onto this outside of here and yeah it's probably the best option
immma take a guess and say you've got it parented and you're trying to override the rotation but it's fighting
yea that setup of setting the rotation of 3 things looks questionable
I'd also suggest debug log the two xyrot values, but cinemachine is the better choice
Were you calling the function inside FixedUpdate?
no
Should I be learning Unity 6 or is 2022 still more stable?
they're overall pretty similar
2022 is probably slightly more stable? π€·
I'm assumming there's more tutorials around the 2022 version? or are they similar enough to the point where those tutorials should still apply?
There might be a few parts of the API that have different naming for some things in 6 compared to 2022 (for example, rigidbody .velocity in 2022 is .linearVelocity in 6 for reasons), and there might be some visual changes but functionally 2022 tutorials should work fine in 6, even older 2018/early 2K tutorials should largely be fine too
Got it. Thanks! Would you say that most have switched to 6 by now or is it still fairly new?
For some devs, its not uncommon to have multiple Unity versions installed for various projects, some ongoing projects might find it better to stick to a particular version instead of dealing with the possible issues that can happen with upgrading/downgrading a project, some devs use different versions to support older assets, some may even just want to try out the newest features, others may see no reason in using 6 for technical or other reasons, but unlike OS updates, Unity versions are one of those things you dont absolutely NEED the latest version, you can use any version for as long as you want (albeit, some versions may have LTS (Long-Term Support) updates and others are "as-is" so any issues with non-LTS versions will not get patched in the future)
I'm using 6 and it works just fine
I have a question. Has anyone been able to integrate unity level play into their project without issue?
I would consider myself a competent fledgeling game developer. But, I have never encountered a more challenging task than this. I have endured four days of agonizing troubleshooting and I am still incapable of getting ads to run on my game
I tried rolling back to the legacy ad system and just kind of forgetting about using a mediation system
But, I am still getting these stupid windows32 errors where the android dependency resolver freezes. Then i put the gradlew.bat file into the temp folder like internet forums suggest. Then it starts resolving but then fails again. Im dealing with such significant frustration from this that I am starting to doubt myself and my skills even though I have been coding for well over three years now
Sorry. I'm aware it's inappropriate to vent my frustrations like this on here. Honestly, I am just looking for some help from a more experienced developer
Maybe this is a sign to shift my monetization strategy away from advertising lol
has anyone used the firestore sdk? im having problem with the constructors. they are being called twice in deserialization and after Start()
Could anyone help me with my problem? I am making a carcontroller and want to use my own system (so not using unity's wheel colliders). In the Wheel script it seems to go wrong but I cant find why. It starts wobbling side to side when on low speeds. I think it could maby have something to do with unity's way of calculating physics but im not sure, maby im just doing something fundementaly wrong.
Wheel script: https://paste.myst.rs/lz3oz71v
Suspension script: https://paste.myst.rs/osd53mbd
WeightDistribution script: https://paste.myst.rs/dklxwo3a
a powerful website for storing and sharing text and code snippets. completely free and open source.
a powerful website for storing and sharing text and code snippets. completely free and open source.
a powerful website for storing and sharing text and code snippets. completely free and open source.
Here also a small video of the problem. The green lines are the velocity of the main rigidbody and the red stripes are the suspension force.
How can i go about playing an animation in reverse from its current frame, as in, if its halfway through, it will start playing backwards from that halfway mark.
why not make it half as long and ping-pong it?
i mean thats kinda what im trying to do, but from any frame
Hmm you probably need to do it per-state with AnimationState.speed
Or use a float parameter and use it as a speed modifier for all the states you want to be able to reverse
ah, "half" was an example, mb.
use .mp4 so it's embedded in discord.
convert it online or something
(btw, why not unity's system? did you have issues with it, or do you just want to make your own for learning purposes?)
I don't see anything wobbling except the green lines
They appear wobbly when the velocity is near zero and you are normalizing it
So I don't think it's an issue really?
If it actually has some physical issues you can try smoothing/damping the forces somehow so it's not as jittery
thats exactly the problem. The velocity is inconsistent. the car doesnt stand still in the example so ill send another video but it really is a problem
it doesn't seem to actually be deviating from the path though. have you tried not normalizing the vector? do you still notice the wobble then?
here you can see the problem better. i prefer not smoothening the grip since it isnt going to feel right but rather floaty and the requirements i got was explicitly not to make it floaty. any other sugestions on what could solve it?
yes i tried not normalizing it and it didnt really make a difference.
ah i see.
what about just damping the speed?
yeah
Btw, I see you moving the wheel in Update.
Better keep its visual as a separate object and control its position in update, and control the physical wheel in FixedUpdate instead
if you have a dynamic rigidbody, you could apply damping/drag on that
Otherwise you introduce framerate dependency here
I was thinking you can damp the individual forces of each suspension point over time, to avoid harsh movements
so you are saying the clamping of the wheel should be done in the fixed update?
Yeah. Pretty minor thing, but thought I'd point it out
physics should be done in fixedupdate in general
You generally don't want anything in Update affecting stuff in FixedUpdate
Except for some inputs ofc
Not a minor thing now that I think about it
i get what you mean, minor mistake. it didnt solve the problem tho. i also tried to do some things with the built in dampening of the rigidbody but it doesnt seem to make a difference
is it dynamic or kinematic?
dynamic
yeah when you mentioned it i was already thinking how stupid it was XD
^Talking about Suspension.ApplyForce here
i dont know if thats the problem tho since the suspension worked perfectly before the wheel script was made. i did add anti roll bars in after posting here that should effectively do a similar thing and i hoped that would maby solve the problem since it was another kind of dampening in the system but it didnt seem to help.
i have a feeling this problem might be a bit harder to solve than a dampening factor. i hoped i maby made a small mistake in coding it and somebody would maby find it here. i have already searched for hours on the internet and got experienced coworkers check it but nobody seems to find the problem
Does it happen if you disable UpdateLateralGrip?
if it helps to mention i am at unity version 6000.0.40f1
You can also see physics settings like "default velocity iterations" or a smaller fixed timestep to see if it's just a physics instability issue. Doubt it tho
no it doesnt. when i turn UpdateLateralGrip off it only slides off the ramp but all the suspension dampening is really smooth
So your issue is somewhere in there
yeah, i dont know where tho
I'd try damping that but you seem really convinced that it's not a damping issue
So π€·ββοΈ
i made a script in a 2022lts about a year ago doing the same thing but with a calculation in velocity instead of weight on the tyre to calculate it and that worked fine but the system used colliders which i cannot for this project. i also cannot change any physics settings because it has to go into a really big existing project.
Yeah, using physical colliders for wheels sounds like a pain
i dont know but i got the instructions to make it feel great and since i have made some similar stuff in the past i am relatively certain it wont feel like they expect it to
i was thinking it might have something to do with the way it is applied and stuff like that but i have already tried a lot of stuff that didnt work
I feel like you should scale the slip force with your current speed
chatgpt has told me it might be floating point errors but it seems so extreme for floating point problems. it already starts doing it at around 1.5 on the velocity.magnitude
i could maby look into this. i have lunch break in 5 minutes but ill certainly check that option
does anyone know how to fix this??
here's the code (ignore the croatian comments, this is for school)
i have more scripts but i believe this one's the one that needs tweaking
This script spawns pipes on its own position (with a random Y offset).
So you should move the object that has this script, to the right
In the editor
omg thank you!
"this behavior" refers to the instance of the script right?
the keyword this ?
behaviour
like for stopAllCoruntines()
its all of them in that instance of the script yes?
thank you
Cool stuff! It looks like either floating precision error or because you are not using the physics system, the steps are calculated faster and thus the camera (Who's probably following it in the Update loop, called 100's of times) is getting a small reposition every frame, not physics frame: https://docs.unity3d.com/6000.0/Documentation/Manual/execution-order.html (scroll down for the Script lifecycle flowchart)
Every frame depends on your computer speed and physics frame is ~60 a second. You usually see this kind of behaviour in Unity too when you are following a Rigidbody object with the camera in an update loop (That's why we have LateUpdate, an update after game logic/physics calculations) . Just a thought π .
hello, I'm just getting started in Unity, I have an error or I don't know what it is going to, I want to create a GameManager but when I create the Scrip it does not adopt the nut icon and will not react as it should, I think it is due to an error of the Unity since the same thing happens when creating a new project, I'm on the latest version
ok, do you actually have an error? or just an issue in general
It would be a general problem since the console does not show any error in the compilation, when creating the GameManager with Monobehaviur it does not adopt the nut icon, or well I don't know much about the subject
I want to upgrade to an LTS version to see if the error persists
i mean, what's the issue there?
GameManager is only special with the icon, it works the same as any other script
π€¨ if you were on latest you should already be on an lts version
I was not in an alpha. π
the latest version isn't on alpha
ah well.. the latest as in highest version number is alpha, i was looking at the wrong column
but you really don't need that
just use full releases
Is there any easy way to track variable references when its being passed by reference between methods? As in if I have a variable _position...
A call is being made to MoveCharacter( _position, _velocity, etc... )
MoveCharacter method header is ( ref position, ref velocity, etc.... ) and inside the method it calls more methods which again have method headers where its inputs are being passed with ref keyword.
So a method 2-3 calls deep is making its way back to modifying the variable I really care about _position. I know visual studio has a way to check for references, but only 1 layer deep. It's not tracking if its being passed to more methods by reference. My code base isn't massive or anything so it's not like it would be very difficult to brute force it but I don't know if there's a tool that can do it for me so the human element is taken out of the equation
Not 100% certain if this is the best way but it is one way you could try - you could make your variable a property and use an observer pattern (event in your property setter) then you can have some debugger script subscribe to that and print the stacktrace, or you could just log the Environment.Stacktrace from the functions your variable is passed, or you could try using breakpoints, I believe in VS you can "watch" variable changes this way
I don't know of a static analyzing tool that does this. It would be possible up to a point; there are also ref variables that can be dynamically set. ref is nothing more than a sugar coating on pointers, which are not trivial to keep track of statically.
You have an animation event that doesn't call any functions. You might have added one by accident
so i added an animation by accident?
how do i delete it
is there a way to create curved ui lines?
maybe the spline tool
to some extend line renderer can also do curved lines but more difficult
for spline you can use it to create a mesh , basically what a line renderer does anyway (its a mesh)
i want to avoid rendering 3d on the ui, the only thing i could think of was connect str8 thin images but then i would get corners not curves
which isnt bad if done right
what is the exact usecase?
technically the whole engine is 3D. The mesh would be very simple most 2D sprites are just a quad anyway
u mean just put the quads very close to the camera? dont think it will look right. im making a runtime node editor and want curved lines to connect the nodes
nah.. I was just saying most 2D stuff in unity is just quads.
wouldn't it be easier to make a node editor using something like the Visual Scripting API ?
or now I think unity also put the GraphAPI or whatever
those dont work in runtime unfortunately
althought they may make the new graph tool work in runtime at some point
hmm I think the new Graphics API did that but i can't find the exact link
yeah I'm trying to find it
its what the new Behavior graph uses
ugh
seems down now?
balls
could've sworne runtime was mentioned but ig it was another thread requesting it.. unfortunate
the only thing I can think is using Splines, the most straight forward way
there is GL but thats pretty advanced and probably overkill here
Line Renderer / Spline imo is the easiest way
How can this be implemented?
Do you guys know how I can get this field's value through code?
at runtime or for editor code? the above link is under UnityEditor
Yeah at runtime π
ah whoops
for Splines you can set up the path / points then put a mesh between those points.
for line renderer you do the same but adding curves would involve some special technique forgot the name, I can find it rq
edit :
there is another one for line renderer but forgot the name
https://www.gamedeveloper.com/business/how-to-work-with-bezier-curve-in-games-with-unity
The main objective of this blog post is to give you a basic idea about how to work with Bezier Curve In Games.
(it isn't)
(i only read the first 4 letters, the rest is extrapolation)
lol it really looked the same at first
Ok I looked at that already but got caught up on how we only have an animation clip and not an animation
can you elaborate?
im confused what you mean by this, the clip is the animation thats playing
animationclip -> actual animation data
animation -> component that run animationclips
animator -> component with a state tree to run animationclips
Right, the clip is the actual animation. The Animation state is what is holding the speed variable.
Ty, and how can that be rendered in the ui? Hope render texture is not the only way
Animation clip
Set the canvas to Screen - Camera
Animation state
Here is my code:
IEnumerator PlayAnimationAndAct(string animationToPlay)
{
float animationTimeToComplete = 0f;
float animationSpeed; // Default animation speed
// Wait until animation done
if (animationToPlay == "BackUp")
{
animator.Play(standUpAnimation_BackUp.name);
animationTimeToComplete = standUpAnimation_BackUp.length;
animationSpeed = animator.GetCurrentAnimatorStateInfo(0).speed; // Get current animation speed
print("Animation Speed: " + animationSpeed);
}
else if(animationToPlay == "FaceUp")
{
animator.Play(standUpAnimation_FaceUp.name);
animationTimeToComplete = standUpAnimation_FaceUp.length;
animationSpeed = animator.GetCurrentAnimatorStateInfo(0).speed; // Get current animation speed
print("Animation Speed: " + animationSpeed);
}
yield return new WaitForSeconds(animationTimeToComplete);
// Set variables
SetCanMoveAndLookToTrue();
}
@ionic grove what's your question and what are you trying to do?
you should probably just use that parameter checkbox, then set that float param through code instead
using the multiplier
Yeah that's an idea. I could just do that
I figured I wouldn't have to because there would be an easy way to get that value, but I guess not
ok, but, why exactly? sounds a bit like an https://xyproblem.info
Because the animation clip length is longer than how long it takes to complete because my animator changed the speed of the animation state
well, no, it's just that length but scaled, and how's that an issue?
It's not an issue.... It's just that I'm altering variable values when the animation is done. So the game thinks it's taking "X" seconds to complete when really it's taking "X/Y" seconds to complete
why not use animation events?
that way you don't have to deal with time at all, and you would just let the animator handle that
if animation events aren't what you're looking for, then
So the game thinks
π€¨ can you be more specific here about "the game thinks"
Now that's a better idea
ah, so it was x/y problem, lol
wait were you pointing at motion or speed here lmao
Speeeeeeeeeeeeeeeeeeeeeed
that makes much more sense to the rest of your questions lol
you didn't actually say what you wanted in the message, the arrow looked like it was pointing to motion to me lol
Honestly not a huge fan of either approach (probably cause I dont fully understand animation transitions) but I do instead try to define stuff like this in code and inspector. The code dictates how long it should take, and tells the animation it, adjusting the speed multiplier
Yeah I don't understand how this isn't a simpler process. I don't like the whole set float thing either, but at least then my animator can set it in the inspector
i do remember having cases where animation events didnt trigger as i wanted it to. also its just a huge pain in the ass to setup
since your case seems to be solvable with events, this is just out of curiosity; what did you mean by this?
oh also; timelines are also another option, but iirc that's a pain to make work with animators
It meant that the time to complete the animation is now length / speed. But my code just sees length right now, so it's taking too long when the speed is set to 1.75
well your code example specifically is part of what i meant "huge fan of either approach". yours has hardcoded strings and is reading the value. What i setup in the past was specifically declaring (like on a component) how long it should take, and then adjusting the speed multiplier as needed
As someone who has tried to animate things using the legacy animation system - trust me, this is much better. The legacy system was such an absolute clusterfuck you basically couldn't do anything more complex than "Play this one animation straight through at this moment in time"
The current Animator workflow with transitions and parameters is capable of taking so much of the cognitive load off of you it's very much worth learning
You can look at VRChat avatars, every single bit of functionality those have is driven almost entirely by the animator and parameters
I believe it. However, I just develop and would like to stay as far away from animating as possible π
honestly, the animator is your best friend
its useful for sooooo much
it can do very simple functionality quite fast
But I'm scared π
its really not hard!
its basically just a timeline
also animation is fun! you can add a ton of juice just by messing around with animation scale, color, position, rotation
But I can't drive myself nuts trying to proceedurally animate things before my animator gets things done then lol
sounds like me ~3 years ago
Animator is sweet but I never get the chance to use it
Make Avatars for VRChat, then it'll be literally your only tool and you'll wish you could actually code something in no time
Really if I didnt have to bloat my project with controllers id use them more over tweens
Vrchat creation does sound like fun though. Need to really figure out bone and cloth physics more
It's definitely one of those "When all you have is a hammer" things. But it turns out most problems can be reduced to a series of nails
Curious, is the visual scripting system possible to leverage in a similar way to scriptable objects?
Case in point: Iβm building a suite of βcodeless toolsβ so my team can contribute content without needing to follow c#. In this case I was thinking about a way to build something like a quest storyboard.
Could I leverage visual scripting engine to make that easy to put together or would I be better off making my own abstraction and making custom UXML editor?
I wanted to leverage the graph/node format similar to shader graph
there's this..but.. https://discussions.unity.com/t/unity-graph-toolkit-update-q1-2025/1614727
third party option https://github.com/alelievr/NodeGraphProcessor
unsupported for non-internal use, untested. But looks cool af
https://docs.unity3d.com/Packages/com.unity.dt.app-ui@1.2/manual/index.html
been trying to do a few tools myself so I've been where you at lol
how do i code a spinning text mesh
spin in which way? thats pretty vague
Which have you settled on?
spin on Z axis
I haven't had time to try the others, I was going to wait for the new one but meantime use the Visual Scripting graph I think thats what shadergraph used before merge to Graph toolkit ?
I donβt need a whole lot of bells or whistles, just a way to use custom scripts for advanced purposes. Yeah I think VS looked close to viable for this
I got the custom scripts support into my cinematics framework but the whole thing is just a linear array editor
Being able to work it up to something like a graph/node based workflow would be ideal
I think that the most mature of them all and probably easier to integrate as running code rn VS one
Iβll have time to explore it tomorrow Iβm just not gonna be at my pc all night to see if my theory was right
Thanks for the info
what have you tried so far ?
also this sounds like a question for #π»βcode-beginner
nothing i cant code π
well use an animation then or learn the basics at !learn π½
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
ty
do buttons need textMesh attached to work??
the two aren't related , so no
i swear my buttons only started working when i gave them a textmesh wth
well you need some type of raycast target probably why
oh
if you put a blank Image component it would work too for example
does the button shape itself not count?
the button uses whatever shape the target is
keep in mind Button is just a component, what Unity does for the premade button is just combining the image component with that button component, then TMP Is just a child
thank you
why is it displaying white and not the selected color (was set that color in script)
as soon as i edit it at all it turns back to the purple
but like
why is it white π
look at the docs for color. you're probably giving it values greater than 1
oh
Hey everyone, I was just wondering if its a good idea to child the camera to a moving first person character with animations. It works well with 50+ fps but under that(or fluctuating fps) I could notice a lot of jitter and snappy movement of the camera. The only reason I am using this as a solution cuz I want the camera movement to be realistic. Is there any other way I could produce a similar effect. Thank you.
obligatory: use cinemachine
alright, I will try
w h a t
anyone using the localization package? how can I force it to halt loading locale on game start?
I want to reproduce an error from a webgl build
I am trying to get a localized string somewhere before making sure the localization is loaded
alternatively since I am always seeing 2 errors I can just add debug logs to all my localized strings calls to see at first 2 but I have no idea how to
any visual studio code way to add a new string under all strings containing matching code?
find in project & replace?
ctrl+shift+f
I have like 100 calls
im not sure i understand what you want
ah, this? yeah find in project & replace could do that
write a regex to match the call you're targetting to add debug.logs
regex π’
the issue is that I am using GetLocalizedString not on just it's own but also to build strings
if you say regex can help with inserting code, well, good to know, but I ain't going to this rabbithole yet
doesn't sound too hard in this case
if you could show a few examples of what you want to debug, i could write one for you
I am having 2 use cases for GetLocalizedString(), I either assign text.text = something.GetLocalizedString(); or text.text = something.GetLocalizedString() + "something" + "optionally something else"; ect
either way it's not a huge deal for me to debug manually and those errors are not causing anything bad
I am mostly asking all that out of curiosity to learn how to be handling that properly
well this is kinda a bodge, but giving that it's for debugging, it's probably fine lol
I would honestly don't mind being able to just redefine localization method for getting localized strings to insert a debug into it
this sounds more simple
or as I was saying at the start find a way to make getting localization very slow so errors pop up in the editor
what would you be debugging here?
as in, what to put in the debug.log
(also interpolated strings exist, might want to try those)
well nothing since I just need to see the first 2 calls (hopefully they are the ones causing errors, if not, well, it sucks)
and logs have a bunch of info if you click on them in console
^(?=( +).+something\.GetLocalizedString\(\)) replace with $1Debug.Log("call"); //--\n
the //-- is just you can search to remove them later
looks ominous
it really is just "find the thing and put a debug before it"
the $1 is to get proper indentation
this wouldn't work if the statement with the localization were a 1-statement if or something like that though
i wonder if c# has the comma operator one sec
where do I even type in and execute the regex?
in search, ctrl+shift+f
so it does, this could be made working with single-statement ifs/whiles/fors if you want
but it'd be harder to remove
(this is for your entire project, use the normal find & replace for a single file)
(and you can filter by file extension/name with the 3 dots)
what does "something" there
well that's what you gave as an example of the call to match lol
if "something" can be arbitrary, you can use \w+ for any identifier
alr I will just give the actual code sample I use
string multiplierString = multiplierPreString.GetLocalizedString() + " x" + currentMultiplerString;
is it always multiplierPreString or can it be some other name?
the point of GetLocalizedString is that you call it for different variables
aka localized strings
aight, so use \w+
you are getting a string.... out of a string
right, but i don't know if you're using existing constants directly or if it's in a function where they all end up with the same parameter name
i don't know how specific you want to get lol
right, was bold to assume everyone know the specifics of this package
anyway I have no idea what do you mean by use
ah sorry
^(?=( +).+\w+\.GetLocalizedString\(\)) replace with $1Debug.Log("call"); //--\n
^(?=( +).+\w+.GetLocalizedString()) something like that not workign
make sure you've selected regex mode
now it works ><
Regex looks so insane to the untrained eye
true
if you want a different debug message, just change it in the replacement
it's pretty much plaintext except for escapes \x or replacements $x (for any x)
well, it worked (also it did find my old code commented away but whatever I take this collateral)
I guess I will have to learn regex at some point
ah, forgot to check for that
how can it not look insane
like.. just look at it
for a moment I thought that the idea of finding and replacing code using vague word descriptions would be a perfect fit for a neural network but then I realized it would botch it harder than people
brief explanation:
^ is an anchor, it matches the beginning of a line
(?= ) is a lookahead, it checks the following text without matching it
( ) is a capture group, it captures whatever it matches to be used later (as \1 or $1, since this is the first capture group)
+ matches multiple spaces. ( +) is used to grab the indent depth (though should probably be ( *) to handle unindented code; + requires at least one)
. matches any character other than newlines, .+ matches a section of any character (this should probably also be .* to handle the general case)
\w is any word character, aka a-z, A-Z, 0-9, and underscores. \w+ is a section of any word character, to match an identifier.
the rest is literal matching, \., \(, and \) are escaped to avoid regex features
the entire regex matches a 0-character string that's followed by the call in question; specifically, it's at the beginning of the line
i'm using a lookahead here to not match the call in question, so we don't have to add it back in when doing the replace
since it's at the start of the line, and the replacement ends with \n, this basically adds another line before the targetted line
$1 in the replacement grabs the first capture group, the indentation depth, then the rest is literal
I have already peeked regex symbols and get scared, you don't have to project my phobia here too
for a detailed explanation, copy the regex into https://regex101.com
Quite literally half of it is to denote stuff like how many occurrences of a character you want, and backslash for special characters or predefined groups \w being for words
It's really not complicated to use. In most cases, if you're using it in a really complex way, it's the wrong way to be doing something
And yea regex101 is a must use tool. It describes it step by step
then you get to the weird stuff like matching emails π
or valid dates, accounting for leap years
or emojis, including combining emojis
In the problem of matching emails, it's gotten more accepted to go with the naive approach
Because there are a lot of cases where a solution is proposed and whoops one user suddenly doesnt work
hey, i never said practical stuff lol. just weird π
ah man there's probably a regex for urls with punycode support lmao
True, what I said above also kinda addresses the whole issue of regex. Like it's usually just a waste to validate everything with regex when its miles easier just directly in code. Leap year being just math
I've always found it weird when people who learned it claim regex is insanely hard. There is almost always an easier alternate solution
Not directly talking about the case above cause that actually requires regex for the built in search
I only heard bad things about regex so I am withstanding to learn it so far
also this is like the first time I have encountered a need for it
I've used it in the past in similar conditions, mass editing text in my ide. If you learn the absolute basics of it, you'll be able to play around in regex101 and get the result you want
no wait ti's the second time... first time I just went for manual editing like 30 times
I'd assume that's mostly comments from people studying it in uni, or people just repeating it cause haha funny. The basics of it is simple, and then complex regex is almost never needed. Even then a complex regex is just a combination of a bunch of simple regex
complex code is just a combination of a bunch of simple code
biggest downside to regex is it limits who can help troubleshoot it
I suppose thats the case for all programming languages
well, it's opaque. hard to debug if it doesn't work
unless you have a dedicated debugger like on regex101, but that doesn't always help. it's kind of an esoteric system
it is just a state machine, but damn is it a complicated state machine
benefit of it being esoteric is you get bragging rights!
Once I tried writing a regex and I accidentally summoned a demon instead
It is quite convenient for simple stuffs, but for complex stuffs regex code basically becomes read only.
Not sure if mentioned here, but Regex is one of those things that language model AIs are pretty good at. They can both break them down to explain them but also construct them. Something with how regex is a pattern system and AI excels at patterns. Might be a useful tool for debugging them too.
https://regex101.com better.
You would of course copy it to regex101 to test it, they aren't mutually exclusive tools, rather complimentary ones
regexes are more finite than code, probably just more examples to directly copy
but still, nowhere near a guarantee
besides, different flavors and newer features exist
Can you check if the phone is using dark mode
there isn't any built in unity method afaik. you can probably easily call the native scripts though to do so
it will probably be wayyy wasier for android
oh there ya go lol
Chatgpt says βIf youβre using Unity UI Toolkit, you can detect dark mode in Application.themeβ
I guess they implemented it in newer versions
is not possible GPT invented something ? seems the usual for me
The newest api doc for application
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Application.html
Yea seems like chatgpt made it up
not surprised
regex is actually pretty simple when you understand the base.
There is mostly only 4 symbols, every other are a combination of them.
( ) (Grouping), * (Kleene Star) , β
(Concatenation) and | (Union). The theory come principally from finite state machine.
what flavor of regex is this
this is definitely not typical regex
i don't know of any flavors that use the middle dot
i think you're talking about a different kind of regex? in cs?
The middle dot is the formal notation of a concatenation in formal language which regex come mostly from.
yeah, in formal language. regex doesn't use it
Obviously, that is beside my point.
it's not really obvious. it seems like you're talking about actual regex, especially when you say there's only 4 symbols
the perceived complexity in regex comes a lot from how many special symbols there are
It would be more accurate to say that there is mostly 4 operator.
sure
It is way simpler then it seem because most of the symbols are a quicker way to write the operation I just said.
tbh though, i think for learning just to use regex, using the regex terms would make more sense
sets, quantifiers, anchors, and groups
does Physics2D.CircleCastAll find colliders that are inside (not intersecting) the initial circle? If so is it because it is able to detect points inside the circle, or it notices the collider intersection as the shape exits the circle that is being dragged
OverlapCircleAll is an instaneous circle-shaped check
ther eis no such thing as the "initial" circle
or things "entering" or "exiting"
whoops I meant circleCastAll
Yes 2D raycast and raycast-like queries detect colliders that overlap the start of the cast
Thanks
This can be configured with this setting https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Physics2D-queriesStartInColliders.html
note that 3D is different
In 3D it never detects such things
what in the name of all things magical causes unity to register clicks somewhere other than the button? π
I'm building a menu for my VR game
for reason's i can't begin to fathom, The click is not being triggered on the button, but below it.... it's as if the trigger area didn't resize/move with the Rect Transform π€
in the video is a bog-standard UI button, which is a child of a world canvas (sorry, I'm so new at game dev i don't even know what to offer in the way of context)
I could do with some help here This is a bug in Unity.... the issue is not there when you build and run the game
pretty sure world canvas is still not a thing for VR. isn't it ?
I meant world space
understandable
bloody nightmare having to put on/take off/recharge my headset every 5 minutes 
yah for me its not having it a headset, maybe you need a special type of Input module, I have no idea
I'll forward this on to #π₯½βvirtual-reality my bad for missing it in the list π
Using ScriptableObjects as a basis for an inventory/item system is common in Unity, but how do people deal with it when item state is mutable and needs to be persistent? For example if items have a bunch of stats on them that need to be saved.
void Start() {
MyItem = ScriptableObject.Instantiate(MyItem);
MyItem.DamageStat += 10; // this only changes this local runtime SO, not the base on in your project
}```
Create a clone you can edit without affecting the original base stats.
That said, I've kinda fallen out of love with SOs when it comes to mutable stuff and mostly use plain c# classes with the serializereference attribute
Is there any implementet function for finding (k) biggest elements ? k<< n
var closestGameObjects = gameObjects
.OrderBy(go => (go.transform.position - origin).sqrMagnitude)
.Take(5)
.ToList();
that part of code have O(n) or O(nlogn ) ?
ScriptableObject asset should be treated as template. Depending on the game, you will want to either create an instance of a ScriptableObject, or create some sort of class that can wrap reference to the template and overridden stats. The second approach is more flexible, because you have an easy access to the template (which is useful if for some reason you want to restore the default state) and lets you easily swap templates without having to make a deep copy of it. But with enough effort, you will be able to achieve same goal with a single instance.
Wrapping it might be more performant in multiplayer games, because syncing whole object could take longer than syncing data about overridden fields. But it might be the opposite, if you're always overriding most of fields.
I'm still in my runtime SO usage arc so I haven't implemented anything like this before but is there a solid pattern to this kind of thing where your base is an Interface that both a base class and the scriptableobject inherit from that creates like a common and paired matching between them?
Sorting algorithms take nlog(n) operations.
When it comes to dynamically sorting elements, you can speed it up by preprocessing data into a self-balancing binary search tree. Modifying 1 element has O(log(n)) cost (where n is the number of elements in collection), but you would be able to retrieve k objects in time O(k), which works well for small k.
https://en.wikipedia.org/wiki/Self-balancing_binary_search_tree
But this solution wouldn't be efficient if you updated whole collection before accessing results (which is what will most likely happen, if you're comparing positions of objects that move every frame). Treat it as good solution for sorting,
If you're working with positions, then I would suggest trying a quad tree instead (or its 3D version). It's great for finding nearest elements.
https://en.wikipedia.org/wiki/Quadtree
Move obiect (i detect object in range) i know that you can do it in O(n) if k is much smaller than n
I was not sure about that build in function (maybe it actually don"t make a sorting)
how large is the list? id really just sort it and use the first X elements. the performance wont matter unless this list is like 1 million objects. In that case, you'd have that many objects in your scene and the game wouldnt run anyways
Is there a reason to use a continuous extension of linear interpolation based on deltaTime instead of just calling it normally in a fixed update frame?
For anyone unaware, Lerp(a, b, f) called every second can be extrapolated into the equation
y=(a-b) (1-f)^x + b, where x is a float representing the number of seconds passed.
This would allow it to be called every Update() instead of every FixedUpdate(). Does anyone think this is useful?
you already can call Lerp in Update provided you are actually using it correctly
https://unity.huh.how/lerp/overview
a lot of what you're saying implies that you need to call Lerp in fixed update, you dont need to
I know I can call it in Update, but then the amount of movement obviously depends on the framrate. My equation keeps the movement based on deltaTime.
then the amount of movement obviously depends on the framrate
not if you use it correctly
Alright then, how do you use it correctly?
accumulate deltaTime in a variable, divide that by desired number of seconds the lerp should take and use that as the t value
Oh, you're assuming that I want the lerped value to move the same amount every frame.
I don't.
i am assuming you want to use lerp over a specific period of time which is what lerp is for
I use Lerp to move something by a certain factor to a certain target every frame, so that it starts at a high velocity moving toward it and slows down as it nears the target.
just saying, i dont think your equation makes sense either. it isnt the same as how you're supposed to use lerp, and suddenly you have 4 variables instead of 3
starts at a high velocity moving toward it and slows down as it nears the target
this is not linear interpolation, this is just smoothing movement
also from that same page i linked before, here is how the link to how you can achieve what you want with lerp (even though you really shouldn't) https://unity.huh.how/lerp/wrong-lerp
Why shouldn't I do that?
also fixed update vs update shouldn't even be a choice here due to lerp. you use update if you want things to happen every frame. you use fixed update for physics stuff so it happens along side unitys physics loop
because there are other methods for that
What other methods?
have you checked the docs?
I've never considered that there could be other methods for what I want but Lerp, so no
how to make a variable public and readonly but modifiable in inspector
can't
readonly makes it not serializable
https://docs.unity3d.com/6000.0/Documentation/Manual/script-serialization-rules.html
public property with private getter + SerializeField attribute targeting the backing field. Doesn't make it read-only from the class but other scripts won't be able to modify it which is what I assume you want
alternatively, private serialized field + public getter which is less brittle but not as slick
its a shame unity doesn't have a nice working readonly attribute
Don't crosspost.
Hello, does Unity provide any sort of info on whether the user is actively resizing the window? I would like to enforce the width and height to be an even number but not when the user is actively resizing the window.
I mostly need to know that the user is done with resizing
You need to make your own by polling screen resolution and potentially input state you want to use. Likely though a window being resized will mean the app may not receive input while doing so, or even update.
If i have a BaseClass, and then ChildClass1 and ChildClass2, all are serializable. How can i have a list of BaseClass and create/edit instances of childClasses in editor?
really dont want to create a custom editor
If it doesnβt update during that may actually already solve it then. I want to prevent the window adjusting when someone is resizing. Iβll go and test it and see what happens
so what you're saying is its not possible without a custom editor?
You need to use SerializeReference, it has no drawer for null by default
There are various packages out there that add a drop-down as a drawer
I think it might still be able to if they stop actually dragging it, but I think youd just need to implement some delay like 0.1 seconds after the resolution last changed
so how are hitboxes and hurtboxes supposed to work?
which one of them are supposed to be trigger, have rigidbody, or both?
i may be wrong, but neither of them is supposed to be a collider with the environment or characters , right? since they only serve to detect attacks and things of that nature
yea
usually hurtboxes are the ones that scan for hitboxes and if they detect one, they deal damage to their owner
so hurtboxes are the things that take damage
and hitboxes deal damage
right
because usually there are more hitboxes than hurtboxes
hereΒ΄s my hitbox and my enemyΒ΄s hurtbox
the problem im having rn is that ontriggerenter is triggering multiple times
and the way that my hitbox works is that it gets enabled and disabled inside the attack animation
usually the solution to that is having iframes, basically a fraction of a second of invincibility once something gets hit
so whatΒ΄s the point of OnTriggerEnter if itΒ΄s not gonna check only once?
usually it only gets called once, not sure why it's getting called multiple times tbh
iΒ΄ve seen around that if a trigger collides with another trigger it causes issues
and that at least one of the parties needs to be a collider or have a rigidbody
okay, i seem to have fixed the issue
it was the animationΒ΄s fault that seemed to be activating the hitbox multiple times
but thank you
wdym issues? they don't even interact
Hello does anyone Have good ressources for UI architecture ? I'm currently trying to do everything or most with UI toolkit
How can i call a functions after a few seconds in update (like looped) as in every 5 seconds an enemy spawns or smt
the simplest way I'd do is have a float that I'd set to a value of 5, every update do timer -= Time.deltaTime. then when timer <= 0f, do whatever it is you want and then reset it back to 5
coroutine
yeah, thats the other way
ty
https://paste.ofcode.org/ahKmTCq5hcKNPUvVupEb9v
So, I'm trying to initiate a command for Yarnspinner where I enter a command named objectEnable, alongside the name of an object, into my Yarn file with the hopes of having the object be enabled when I do so and in the project itself, I'd have the objects disabled beforehand. The problem is, I keep getting a NullReferenceException: Object reference not set to an instance of an object error and I don't know why that is. Can anyone help me figure this out?
Not sure if it counts as "good," but what I did for my project with UI elements is make my own "clickable" parent class that child classes can derive from. Whenever the player clicks, a manager on the player records all of the clickable scripts that were hit by the player, and calls functions like OnMouseDown, OnMouseUp, OnMouseEnter, OnMouseExit, OnHold, and updates a boolean that shows wether a player is hovering over something or not. I found that this approach let me make really robust systems easily, and I avoided a lot of the hassle that comes with UI toolkits by making my own barebones one. If you'd like, I can share the code.
I'm not sure if Yarnspinner can find inactive gameObjects. Try enabling the GO and see if you still get the error.
I still do!
which line is the error? Are you sure you have the dialogueRunner assigned in the inspector? Does the Debug fire in your method?
So, I get this big block of text
https://paste.ofcode.org/A3feE5nCugmzAJ4VebBGVC
It sounds like it's line 270, which is the objectName.SetActive(true);
How about making gliding like this, but using character controller? https://youtu.be/dQq9synN9r8?si=uTR5msd3f3mCMSwp
GitHub Project : https://github.com/SOMENULL/Gliding-Project
Music Attributions :
Music from #Uppbeat (free for Creators!):
https://uppbeat.io/t/kidcut/flamingo
License code: TSGHFYAYFKBMLCIF
Music from #Uppbeat (free for Creators!):
https://uppbeat.io/t/mountaineer/fly-away
License code: VEUQYEESKSSSI4ZN
Music from #Uppbeat (free for Creato...
This is essentially a copy paste I am making from the server whose tutorial I am watching so sorry for it being a little lengthy
Actually nvm
I'll explain it fresh
So I am watching a tutorial rn to make 3D chess
ok, start with the issue and immediate context
and it makes a 8x8 chessboard
we don't need the entire story
the problem is that when I hover it the tile changes layer
but the material doesn't change to the hover material
as you can see in the picture the layer is hover
I've found a unity bug inside code, how do I report it efficiently?
the unity bug tracker
(usual layer is tile) but the material is still the same as all other tiles which aren't being hovered
(since you're here though, wanna run it past us in case it isn't?)
So presumably you have some code that changes the layer. Do you also have code that tries to switch material?
Are both of these pieces of code in the same location?
ok, where are you attempting to change the material?
So I am trying to change the material through the URP asset, with the changeObject feature
both of the materials are transparents
I've done hovering code dozens of times but never used that Renderer Feature I'm afraid 
The raycasting code
Sure, it's more of code missing a line. I'm making use of UnityEditor.Searcher package, and i was calling the method CustomSearchTreeUtility.CreateFromFlatList to ensure that, passed a set of elements like node/type/name they were properly sorted and organized.
However, I wanted to make use of the SearchItems property called Synonims, that basically allow you to add extra words that should return that item. But for some reason, they weren't working.
I checked the code of the package and found that on line 71 of that class there should be an additional
currentSearchNode.Synonyms = item.Synonyms;
to ensure that the synonims are transfered to the new SearchItems, otherwise they are lost
RayCast on every single frame?
they probably forgot to add that
Yep - that is completely fine if it's just like a "one time per frame" thing.
I know there's some controversy around it and bad practices, but that's how all hovering works afaik. And also, you won't see a single RayCast like that make a dent in the profiler.
What is a bad practice is to do that for a bunch of units, if you want something like an ant colony to use RayCasts to avoid bumping into walls, then that would be an issue.
But generally, things that are just for the player character you will have a lot more leeway for
One charater - fine. One frame - fine. Many characters every frame - double-check that.
so i have this movement script that uses swipes on a mobile device to move, how would i translate this into a A & D keyboard movement
private void Update()
{
if (Controls.swiperight == true && Lane3 == false && Lane1 == true)
{
Lane2 = true;
Lane1 = false;
Lane3 = false;
}
else if (Controls.swipeleft == true && Lane2 == true && Player.position.z <= 0.2f)
{
Lane1 = true;
Lane2 = false;
Lane3 = false;
}
else if (Controls.swiperight == true && Lane2 == true && Player.position.z >= -0.2f)
{
Lane3 = true;
Lane1 = false;
Lane2 = false;
}
else if (Controls.swipeleft == true && Lane1 == false && Lane3 == true)
{
Lane2 = true;
Lane1 = false;
Lane3 = false;
}
}
this is like an overconvoluted way of not using an array / index ?
if(input.getKeyDown(KeyCode.D)){ if(currentLane < maxLanes) currentLane ++;
lanes[currentLane]
etc.
!code
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Mr. Chexxor, you said you have done hovering a bunch of times, do you think you could help me implement a way to do it inside of my code π
Or do you have any tutorial suggestions for doing it
and this would be repeated 3 times ?
why 3? you only need to check left bound and right bound
so those 3 lines of could would be enough >?
i would need it for the A key aswell surely
yes just A and D
all you're doing is ++ the index/int or --
Is this the right place to ask netcode and parenting questions?
and post the full question, don't ask to ask
and declare currentLane and maxLanes
right
yes
as bools ?
my Lanes are bools
why are they bools
I'm about to grab some food but at least a couple pointers for now:
-
In your Tile script, add a reference to the tile's Renderer (You will use this to switch materials manually)
-
Add a material field for where to put the default material (so you can switch back when no longer hovering)
- In Awake/Start or similar, set this
ThisTilesMaterial = ThisTilesRenderer.SharedMaterialto save it for later (choose variable naming as you see fit)
- In Awake/Start or similar, set this
-
Add another material field for the
HoverMaterialand assign this in the inspector for each of your tile prefabs if you have those -
Add a method on your tile class to enable/disable hovering
-
In your current RayCast code where you switch layers, call this method as well
- (You could move the layer switching code into this new hovering method)
-
In the hovering method if setting to true then
ThisTilesRenderer.SharedMaterial = HoverMaterialotherwise= ThisTilesMaterial
Store the bools in an array and index them with an int, how about that?
sure that could work but still no idea why they are bools in the first place
Fair enough
if you miss something bools can let you be in 2 different states/lanes at same time
I'd prefer an enum for this tbh
yes enums just numbers with labels
They are one of my favourite language features, i just really like them
I was looking at some GTA Vice City source code and the amount of enums/switches is fantastic lol
no bullshit abstractions for state machines, just good ol plain enums
Source code from where?
github
niceee . I had the gta3 link avail, forgot where i put VC
look at all these enums lmao (gta3 btw)
https://github.com/halpz/re3/blob/310dd8637147c4db643107b69d603902abc78141/src/peds/Ped.h#L133
ped state has over 50 of them..crazy
can someone help me please? I made somewhere in making multiplayer mistake and nothing works when 2 players join xD
#archived-networking and dont ask to ask
dont ask to ask?
yes things like "can someone help me? " etc
just ask your specific question, if someone has/knows the answer they will reply
uhmm thats the problem idk where the mistake I made is basicly when I join with other player every single script is making errors xD
well then you would start by sharing the errors
if you don't know how can a total stranger to the problem possibly know without any context
frankly if your first project is networking you will struggle more than need to
suggest you get more comfortable in unity before doing net
Networking is my second project and my codebase just runs on black magic it feels like
I have way more projects before I tried multiplayer
Enums my beloved
sure, but frankly quantity is not always synonymous with quality
what you learned in experience on those project is much more important
UnassignedReferenceException: The variable rb of NZombie has not been assigned.
You probably need to assign the rb variable of the NZombie script in the inspector.
UnityEngine.Object+MarshalledUnityObject.TryThrowEditorNullExceptionObject (UnityEngine.Object unityObj, System.String parameterName) (at <44f3679c53d1477a9c6e72f269e3a3a9>:0)
UnityEngine.Bindings.ThrowHelper.ThrowNullReferenceException (System.Object obj) (at <44f3679c53d1477a9c6e72f269e3a3a9>:0)
UnityEngine.Rigidbody.get_linearVelocity () (at <33f9ec680d9d4a85b09adc18a20b37f0>:0)
NZombie.MoveTowardsPlayer () (at Assets/Scripts/Zombies/NZombie.cs:28)
NZombie.Update () (at Assets/Scripts/Zombies/NZombie.cs:19)
can someone by any chance help me fix this error?
this isn't even a networking question, this kinda hits that all your projects you did not learn the fundamentals
it tells you in the error what could be wrong
UnassignedReferenceException: The variable rb of NZombie has not been assigned.
You probably need to assign the rb variable of the NZombie script in the inspector.```
I mean the thing that makes me the most like confused is that this zombie is ok with not having RB but the NZombie is having trouble even tho they are parented from the same script
ehy do you have 2 rigidbody variables... Player Rb & Rb ...?!?
the Rb is rigidBody of the zombie
hard to tell from this alone..
one is trying to use it while null, the other isnt
!code
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
please don't use screenshots
so that GetComponent isn't finding a Rigidbody on this script
yea but then why it is finding on the other zombie????
because that zombie has a rb?
yeah you use the RB variable but attached the Rigidbodfy to the Player Rb variable..
look at those 2 objects at runtime
you only need normaly only one Rigidbody for the object..
if you want to be sure, just add a [RequireComponent(typeof(Rigidbody))] to your parent script
they are referencing the player probably to do stuff with it, that part is fine
you use 2 and attached it to the wrong ones
yeah looks like that's the case
and the "player rb" is not the rb of the zombie
in code he uses rb = GetComponent ...
assuming they want to do maybe like a Hit react with AddForce to player or something
not PlayerRb thats the prob
but not playerRb = GetComponent
Just assign rb through the inspector (no need for rb = GetComponent here)
that is not the prob
gimme sec
They didn't mention any issues with playerRB
yeah cause it isnt even used
how do you know?
we havent seen the entire script
in the code above he posted its not in
I mean they showed us 2 functions not the entire script
@sonic portal how is any of that relevant
the problem is with rb, as evidenced by the error
and it's being assigned by GetComponent
that's all
playerRb is completely irrelevant
A tool for sharing your source code with the world!
he just asigns the rb var
whole codes
its possibly playerRB is a hit react
thats what i said ..
yeah how is that relevant to the issue
playerRb isnt even being accessed , so its irrelevant
he asigned the Rigidbody to the PlayerRb.. thats not used
...because it's not the issue? They showed the code for the one that is the issue
ok, that's not relevant though
need to asign it to the Rb
it's completely unrelated
They're different rigidbodies
why would they assign the playerRB to the rb variable
GUYS chill out here is the complete code
They're not related to the problem at all
no need to speculate
the solution is simple
put the rigidbody and assign it in the inspector..
Basically your issue was answered - this object has no rigidbody. P5YLO just keep insisting it was something else
And drowning out the solution
rb = GetComponent<Rigidbody>(); is not needed anyway if you assign it through inspector which you should do for components on the same object
The GetComponent does makes moving scripts around easier by not having to assign everything manually. I do prefer that
I rather be assured everything is assigned then worrying if i ever move a component to a child everything breaks..
DI > runtime
also GetComponent can get unnecessary extra compute time..
Imagine you have thousands of gameobjects with GetComponents in Start /Awake.
You're gonna have a bad startup time
If you can drag it in, you should. It's faster that way, reduces scene load time
π€ i tend to use RequireComponent+GetComponent for that
i guess "good DX" can be different for different people
OnValidate I do use GetComponent some times
but thats editor only anyway and takes care of autoassign
but i haven't made scenes with a ton of objects, so maybe i'll encounter that load time issue later π
It's not a huge benefit, but when it's completely free, why not go for it?
Ig I will continue on my getcomponent ways for now and really consider DI if I reach a scale where the performance impact is significant
dragging "this" object onto itself for multiple slots is worse DX for me
It's just development time convenience in my case
but usually its more handy with children objects
if you have like 10 fields for the same gameobject yeah its a pain lol
but yeah as you said Editor things like RequireComponent or GetComponent in things like OnValidate can mitigate that you get best of both worlds as long as it aint runtime
ah yeah i do use refs in that situation
If you do then I have other questions to ask before that
its not a huge deal esp if you dont have many objects but yeah its free optimizations so why not
wdym?
oh nvm lol I get it
I use a mix of refs and GetComponentInChildren in that case
aside from OnValidate now I only use GetComponent if I need a runtime ref through collision or other queries
but TryGet ofc
we don't have built in TryGetInParent/Child but made extension method for it π
What would the use case of a get comp be in on validate? I'm curious
as you said , if you dont want to manually assign all the fields to components and have them GetComponent before the game start
Cool. I probably should settle with that then
its the next best thing to SerializeField assignment imo
the problem only comes with the same issue at runtime, if you have multiple of the same component (two box colliders) but you want to only work with a specific one, you can't tell GetComponent which one you want as it grabs the first one
if I have problem regarding multiplayer I should go to #archived-networking even tho the problem is somewhere within code?
if its a networking question it goes there, so far you have not posted a networking question so it goes in #π»βcode-beginner
SerializeField + RequireComponent + GetComponent in Reset is super nice. It sets itself up immediately when added to an object in the scene. And isn't running logic unnecessarily every time I make an edit like OnValidate would
Ah
Reset forgot about that lol
Can anyone help me, I'm trying to create a "Map" extension function which will map a value to another one as long as it's set.
// Given
int? i = null;
int j = 4;
AudioClip? c = null;
AudioClip d = /* a non-null audio clip */
i.Map(x => j); // Should be an int? which equals to null
i.Map(x => d); // Should be an AudioClip? which equals to null
c.Map(x => j); // Should be an int? which equals to null
c.Map(x => d); // Should be an AudioClip? which equals to null
I have this so far, but that won't work as it uses default, so when I map to a boolean it'll use false...
public static TResult? Map<TValue, TResult>(this TValue? value, Func<TValue, TResult> fn)
{
return value == null ? default : fn(value);
}
ohhh thought that was a Predicate<T>
nvm this goes beyond my monkee brain forget me.. lol
If I try to return null, it complains with this: Cannot convert expression type 'null' to return type 'TResult?'
Do you just want a Dictionary?
No, I'm just trying to map a value which may be null to another one, just when it isn't null
not sure i understand tbh
The code I'm using it for is this:
TaskResult? maybeResult = audioSource
.Map(src => audioClip.Map(clip => PlayClip(src, clip)))
.Map(x => TaskResult.Success);
The idea being I have an AudioClip? and an AudioSource? and I just want to play a sound if both are not null, then I want to get TaskResult.Success if that worked
Assuming PlayClip never fails of course (it always returns true for now)
wouldn't the code just be way clearer as:
if (audioSource.HasValue && audioClip.HasValue) {
PlayClip(audioSource, audioClip);
result = TaskResult.Success;
}```
Not in the way I'm used to code in π
I guess I need to learn coding much better since I DONT UNDERSTAND THAT AT ALL
using PrimeTween;
using Unity.Cinemachine;
using System;
public class CameraTransition : MonoBehaviour
{
[Header("Cinemachine settings")]
[SerializeField] private CinemachineCamera virtualCam;
[SerializeField] private Transform followTarget;
[Header("Initial values")]
[SerializeField] private Vector3 startPosition = new Vector3(0, 0, -10);
[SerializeField] private float startSize = 10.8f;
[SerializeField] private float waitTime = 2f;
[Header("End values")]
[SerializeField] private float targetSize = 5f;
[SerializeField] private float transitionDuration = 1f;
private void Start()
{
transform.position = startPosition;
virtualCam.Follow = null;
virtualCam.Lens.OrthographicSize = startSize;
Invoke("StartCameraFollow", waitTime);
}
public void StartCameraFollow()
{
// Tweenataan ortho-zoom
Tween.Custom(virtualCam.Lens.OrthographicSize, targetSize, transitionDuration, onValueChange: value =>
{
virtualCam.Lens.OrthographicSize = value;
});
Vector3 destination = new Vector3(followTarget.position.x, followTarget.position.y, startPosition.z);
Tween.Position(transform, destination, transitionDuration)
.OnComplete(() =>
{
virtualCam.Follow = followTarget;
});
}
}```
Quite a long code but my cinemachine does a little down up when I set the followTarget. How can I avoid that?
That's like 6 lines of code, not long lol
as for the "updown" it's not clear just from the code what's causing it
Well That is the only thing attached to the cinemachine
That might be the only piece of your code on the object but there are certainly at least 2 cinemachine components
What I mean is that your configuration of the camera along with the position and behavior of the objects in your scene is causing it most likely
what object are you having it follow
also it seems like your script is also manually moving the object
so it may be fighting with the CM stuff
Its just this player. It doesn't have anything else than sprite now
is this 2d?
you should be using Framing Transposer not CInemachineFollow afaik
the new 3.0 changes are still a bit confusing π
yeah they split some stuff up and confused me lol
worse case scenario i switch to 2.x
Ive been looking to create some voxel destruction similar to games like clone drone in the danger zone. Ive struggled to find any tutorials or templates for it
anyone have any recommendations?
mostly just seems to be a particle or VFX that spawns after the character dies
nah It usually removes cubes from the actual character thats hit
I think there's a combination of effects at play here
- a VFX for the little random cubes that break off
- Possibly replacing the character model with a set of individual MeshRenderers at the moment of death
- the particular renderers that god hit maybe using a "slice" style shader to simulate being sliced to pieces
Oh i see they also can have their legs broken off and stuff - probably just the characters are made of several pre-built pieces (individual MeshRenderers) rather than one SkinnedMeshRenderer
This doesn't scream to me full-fledged voxel engine destruction the way Teardown is for example
where can i upload code to send here
!code
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
So im making an endless runner that will spawn (for the time being) these 3 variations of Tiles that will continously spawn and move away from the camera,
here is my levelgeneration code: https://paste.mod.gg/wjsqnbmxuxzv/0
A tool for sharing your source code with the world!
ok, what's the issue
this is what happens when i run it.
Is it required to use ComputeShader.FindKernel()?
If you have 2 kernels first CSMain for example and then below it CSSecond for example. Will the main one have index 1 and second index 2? Or is it a bit random?
@vestal arch any clue why the tiles are spawning so weirdly
Problem 1 is you need to switch this to Pivot mode.
then look at your prefabs and make sure the root object pivot is correct
and that the prefab root is not offset weirdly
root object being the player ?
no?
the root object is the "main" aka topmost object in the hierarchy of the prefab
talking about the tile prefabs
please don't ping specific people for help
i mean you asked me about it and then didnt reply but all good
root objects pivot is 0 0 0
and are all the children positioned reasonable?
Not hugely offset from the root or something?\
negative
What's the issue exactly then> What are you expecting to happen that isn't happening
note that your code is repeatedly setting th eposition of StartPlane3
Also rather than going down the YandereDev path of "variables nam,ed with numbers after them" and "huge blocks of repeated code" I recommend to take a minute or so to learn to use arrays and lists in C#.
public class MovementController : MonoBehaviour
{
[Header("components")]
[SerializeField] private Rigidbody player_rb;
[SerializeField] private Transform character;
[Header("keybinds")]
[SerializeField] private KeyCode crouch_bind;
[SerializeField] private KeyCode jump_bind;
[Header("movement")]
[SerializeField] private float max_speed;
[SerializeField] private float speed;
[SerializeField] private float drag;
// state
private enum state {
AIR,
WALK,
IDLE,
JUMP,
SLIDE,
CROUCH,
}
private state player_state;
public void state_manager() {
if (player_rb.linearVelocity.magnitude <= 0) {
player_state = state.IDLE;
}
else {
player_state = state.WALK;
}
if (Input.GetKeyDown(crouch_bind)) {
if (player_state == state.IDLE) {
player_state = state.CROUCH;
}
if (player_state == state.WALK) {
player_state = state.SLIDE;
}
}
if (Input.GetKeyDown(jump_bind)) {
if (player_state == state.AIR) {
return;
}
player_state = state.JUMP;
}
if (player_state == state.AIR) {
if (!is_grounded()) {
return;
}
player_state = state.WALK;
}
}
public void slide() {
// early exit
if (player_state != state.SLIDE) {
return;
}
player_rb.AddForce(transform.forward * 10);
// idk how to check if slide ended
player_state = state.WALK;
}
public void jump() {
// early exit
if (player_state != state.JUMP) {
return;
}
player_rb.AddForce(Vector2.up * jump_force);
player_state = state.AIR;
}```
I'm guessing I'm doing it completely wrong
cause it just looks wrong
and there might be even more states let's say wall-running
it woudl probably add like 4 more if clauses
not necessarily but do you need every state rn ? what do they do exactly when in that state?
cause when im in jump state
the jump() function executes
once
and switches to air
cause it would keep adding force
but you can just check if you're AIR to prevent multiple jumps
and your jump should probably use an Impulse rather than applying constant force
if i need
a lot of states
like wall-running
or any others
if i want to extent
scale the system
it looks wrong idk
okay but am i doing this wrong
partially , I would clean it up a bit
starting with the suggestions i've made above
I'm trying to modify all my prefabs material, before a build, to be compatible with WebGL. My issue is that it modifies the actually prefab, not only it's instance in the build. How could I modify my code to only modify it within the build?
you have to do cs instead of csharp with the backticks
csharp works btw
!code
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
it does?!
example
normally large code you send via links
my bad then!
thinking back, i have only ever seen csharp when it comes to blocks of text sending as .txt
both work fine
sure used to do that but we can .txt now?
ah kk
for my issue chatgpt suggests modifying the prefabs then reverting the changes after the build is complete, feels bad but would work most likely
and the prefabs would get corrupted if the build fails
ikr lol
I still don't understand, what exactly needs to be modified here? and why
some of my materials are broken in WebGL
oh like the shader?
you have 2 different versions already yes ?
kinda
Theres a reason the large code block paste exists
Im oldschool..i would just make 2 copies instead of doing it by code
was doing this
if (originalShader.name.Contains("poiyomi", System.StringComparison.OrdinalIgnoreCase)) {
var newMaterial = UnityUtility.CopyMaterial(renderer.sharedMaterial);
renderer.material = newMaterial;
newMaterial.shader = Shader.Find("Stamdard");
newMaterial.SetColor("_FirstOutlineColor", Color.black);
newMaterial.SetFloat("_FirstOutlineWidth", 0.025f);
and then how would you implement the fallback?
discord puts massive walls of text into a .txt file
yeah it kinda sucks on mobile, on pc it shows the .txt
forgot about that
fallback in what sense?
what kind of message would you need to send thats 4000 characters long, to warrant nitro
if my build is webgl, how does it know to use the 2nd material?
could just use seperate prefabs
you're in the editor so you already know you're doing webgl
then same question. how does it know which prefab to use?
i mean desktop builds can use any shaders, just not the webgl ones
cause you're in the editor as WebGL build so you can make for example a WEBGL Boostrapper etc
it doesn't quite work like that, it will still work in play mode, but when you build it will break
(pink materials)
I mean the object you need already has the shader with webgl compatible
all you need is a separate scene to initialize those instead of the "normal ones"
its probably more crude / less programmer friendly but it works, imo is most straight forward
they have all the same scripts anyway so the logic should still work the same
I feel like there has to be a way of doing this during the build instead
sure there is, but more complicated
basically saying yes its a pain cause now you have copies of objects which can introduce annoyance at scale if you forget to change 1 but not the other.
well.. i guess i can just make a custom instantiate method that checks what material the prefab has (if in webgl) and modifies the material when needed
hopefully wont be too slow to do that in the browser
do it during loading but if its a webgl not point to even put in the build the shaders/materials non-compatible
I would understand if you did automated CI/CD deploy but if you're in the editor mind as well do that before build
that's what i was doing IPreprocessBuildWithReport
but it modifies the prefabs
every item in the game pretty much needs that change so doing it by hand is not an option
when i call
if (dataTotal.TryGetValue(kvp.Key, out uint currentValue1))
currentValue1 is always 0 instead of the actual value. Any ideas?
The key isn't present in the dictionary
Thanks! I was using currentValue1 instead of using kvp.Value in the else{}
I'm using cinemachine camera for 2D but whenever I increase the X and Y damping, when I move the player the camera follow but it's not smooth as if the camera act with low fps. I followed a tutorial on youtube and he doesn't experience this problem.
YOu'd have to share how you set everything up
as well as your cinemachine settings (including the brain update mode)
and how your player object is moving
Without camera damping, the player move is very smooth no problem here
This is the brain set on my camera
and this is on my cinemachine camera
Can anyone spot what I'm missing here? No matter what I click, the ID is being set to 1.
this might be a bit of a strange question but is it possible to detect 3d colliders with a physics2d.linecast?
why not a 3d linecast
lambda variable capture
Two different physic APIs
you need to do cs int temp = i - 1; Button listButton = new Button() { portraitID = temp; }
well yeah that's the response i was expecting. but i was just curious if it was possible because i mostly didnt want to spend time rewriting all the 2d ray/line casts into 3d equivalent, so i was looking to see if there was any small workaround.
doesn't look like you can tho
Thank you
was using 2d linecasts and raycasts to detect some collisions, but im in the middle of making some 3d sections and wanted a nice way to switch from 2d colliders and 2d rigid body to 3d without doing too much. but it's probably better i tackle this anyways for learning sake
If you're going to use 3D, then just use the 3D API and forgo the 2D
lock axis if needed
Just to check, did you mean to add the lamda to your example?
yeah
the point is
exactly what you have but with the temp variable
I get it, but it's still not working. Using a temp variable now sets the ID to the array length...
show the new code
looks fine. What makes you say it's setting the ID to the array length?
what are we expecting to see here?
Also you have a lot of other errors π€
Where is that Debug.Log from?
2 secs, gonna try something quick with some debug logs
I check what Portrait ID is set when the DrawActorWindow is called.
where is portaitID declared?
The only other time I change this value is when I click on an actor to load up their details
This is the editor window
When you click an actor it resets the Portrait and Sprite IDs
this question is extremely important
When the Window is created
well that's your problem
you have one portait id for the whole window
not one per button
er.. hmm I guess... this should actually work anyway?
Can you show that Debug.Log?
Which one sorry?
!code
π Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
π Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Show DrawActorWindow
A tool for sharing your source code with the world!
I don't see anything wrong with the code π€
Start adding more logs yeah
Make sure portraitId is not set anywhere else
and put a log every time you do set it.
Only other time I change this value is when the Actor's button is pressed here:
A tool for sharing your source code with the world!
add those logs :p
so I shared my stuff but no one helped me yet.. My camera is jittering when following the player with damping effect.
The other thing I'd like to see is your player
and how you do movement for it