#archived-code-general
1 messages · Page 115 of 1
What I do is keep unique data minimal, and construct stuff relative to what data you can read from in SOs
and instead save IDs to the SOs instead of the data itself
i need to instantiate generic type with parameters. i use T t = (T)Activator.CreateInstance(typeof(T), parameters[]). idk what it is though and i need to run it a lot while it's supposed to be slow. should i just copy paste code instead?
If T has always a parameterless constructor, then you can constrain your type where T : new(), then call new T() immediately. Not possible if you don't have a parameterless constructor
i dont have it
Pretty lame the new constraint is so basic, something like where T : new(int, string, whatever) would have been nice for some cases
Hey uh, quick question : is there a recommended way for unity to implement generic loading ?
By that I mean loading a player's custom resources, like images or additional textures
you can use the file:// protocol to read files with it
I'm thinking more of something like uh, a Mods or Resources folder directly inside of the game's installation folder, and the player just puts his files here :v
Maybe streaming assets?
https://docs.unity3d.com/Manual/StreamingAssets.html
I see that there's AssetsBundle too, but it means having to use Unity to create assets packages ? https://docs.unity3d.com/Manual/AssetBundlesIntro.html
Haven't used steamingassets yet but I'm also interested if it can be used for user-created content
Ye that was my first solution
But I was wondering if Unity provided innate mod or "generic custom loading" support
Oh well
yes it can on PC, not for mobile or WebGL
you need to be looking at Application.persistentDataPath
Yes and once you have such a folder you will want what I linked you in order to read the textures
The Adressables package seems pretty complete for my need
can someone suggest good article/post/video on managing component dependencies? I'm talking about moving from service locator to make prefabs more flexible and self-sustained so I for example, will not have to create the world in order for small UI component to work.
im trying to create a main menu but im experiencing lots of issues with my script. https://pastebin.com/Fdz7VCQU
i want the saveSettingsButton to show up when changes to the 2 dropdowns are made and be hidden whenever i save the changes. however the button does not show up at all and im not quite sure why.
additinally, the confirmationPopup is supposed to show up if i made changes and i didnt save, it doesn't show up whatsoever just like the saveSettingsButton. is anything wrong with it? can anyone please help ive been at this for a couple hours now.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
nowhere do you ever do
settingsChanged = true;
how did i not realize
where exactly do i put it? just in the UpdateApplyButton() function?
because i dont wanna risk getting confused again
apparently that still isn't enough. im really confused
hey, you wrote the code
i wouldn't be asking if i knew what i'm doing wrong
its my first day coding after taking a 1 year break
How could I calculate the middle of two vectors? I don't know what to call it
Let's say I was making a throwable thing for VR and somebody was attempting to throw it. Obviously when your arm reaches the end of the throw its going to go down
If I calculated the velocity the object should be thrown at via current hand position - previous hand position
It would just go straight down
How could I make it so it takes the in-between of like the start and end vector I dunno
Or just make it not go down I suppose?
@languid houndcurrentPosition - lastPosition will give you the current velocity
so I'm not sure what you're talking about
I don't think that's going to work.
Getting the velocity and applying it to the rigidbody on release is probably your best bet
Yes but from my experience the issue is if you let go last minute the object will go down because its calculating the distance between your previous hand position and next one. What I want is to get the average between maybe 5 positions from a couple frames ago so its less jarring and could be more accurate even if not realistic
Then you should force it to calculate between your current and previous position
averaging the last 5 vectors isn't the right solution.
Clearly something is going wrong in your code
Games like Toss use it and get a really good result
Getting an average vector is the exact same as getting an average of numbers. Sum them all, and divide by the item count
Nothing is wrong to my knowledge its just
grabbedRigid.AddForce((currentPosition - prevFramePosition), ForceMode.Impulse)
apply it as a velocity
not force
current - previous is a velocity
velocity specifies movement over time
Applying it as impulse (arg 2) is similar to setting the velocity directly, it just takes the mass in consideration
VR is difficult in general. When picking items up, some people disable the rigidbody component and simply parent the gameobject to the hand
other people use control theory to write PIDs to change the velocity and angular velocity to match the orientation of the hand
so it all really depends on your setup
My game has a camera that is automatically moving up at a fixed velocity. The camera also follows the player at the same time. The problem is that there is extra velocity added to the camera as it adjusts to keep the player in frame. How do i get rid of this extra velocity? Code to control camera movement:
targetPosition = new Vector3(player.transform.position.x,player.transform.position.y+velocityUp,-1); transform.position = Vector3.SmoothDamp(transform.position,targetPosition, ref velocity, smoothTime);
wym extra velocity? Like it overshoots?
my player moves suddenly, so the camera has to accelerate to keep the player in frame
it tries to smoothly follow the player
Still not sure what the issue is
I have an velocity upwards on the camera at all times. If the player exits the view of the camera, the game is over. The problem is that when I move my player abruptly, the camera adds extra velocity upwards which I don't want. So the velocity in my game that is constant is 0.5f. Whenever the camera tries to adjust to ensure the player is in the center of the screen, the velocity upwards becomes 0.5f + some additional velocity
FYI the velocity increase because the distance increases between camera position and target position when player is moved forward rather than when player is standing still. So it lerps faster.
So what Burt said.
The player should be the one trying to maintain a position inside of the screen
not the other way around
I did that initially, but the game looks jarring because of the sudden shifts
just move the camera upward a little bit every frame.
I'm imagining a game like doodle jump or something
but yours might be different
whenever you need the camera to jump to a new position, you could lerp over time
is the camera ALWAYS moving up? Or just in sync with the player?
always
the player has to keep moving up to keep inside the camera's frame
void Update() {
camera.transform.position += new Vector3(0, 0.01f * time.DeltaTime, 0);
}
slowly every frame
before this would I do
camera.transform.position = targetPosition
where targetPosition is the pos of the player?
I mean yeah, that could work
as long as it's getting updated in sync with the player update
I think that would look weird
but then your player can never leave the camera
if you snap camera to player
and can never lose
hmmm
Doodle jump, the camera moves with the player
if player doesn't move, camera doesn't move
but I believe the camera can never move down
it's been a long time since I've played that game
for me, i need the camera to move even if the player is stationary
at all times
alright yeah just move it upwards a little bit every frame then
that should solve your issue
velocityUp = 0.01f*Time.deltaTime; targetPosition = new Vector3(player.transform.position.x, player.transform.position.y+velocityUp ,-1); transform.position = targetPosition;
probably something like that yeah
It should be more like this?
private void Update()
{
// Move camera up on the Y axis
camera.transform.Translate(Vector3.up * moveSpeed * Time.deltaTime);
// Center the camera on the player on the X axis
Vector3 targetPosition = new Vector3(player.position.x, transform.position.y, transform.position.z);
camera.transform.position = Vector3.Lerp(transform.position, targetPosition, lerpSpeed * Time.deltaTime);
}
As long as it works, it doesn't really matter
can't remember the last time I've used the Translate function
I mean his previous one wont work correctly as it sets transform to concrete position of the player for X but Y is also based off player pos.
woops
I meant playfab
@random cipher !collab
We do not accept job or collab posts on discord.
Please use the forums:
• Commercial Job Seeking
• Commercial Job Offering
• Non Commercial Collaboration
What is ur fan game
Most people aren't going to design you a game for free
just gonna put that out there
not to mention there's probably thousands of gorilla tag clones in unity, based on how much I read about it in this chat
that works thank you for the help. only problem is if the player goes at the top of the screen, the camera accelerates really fast to the point where its near impossible for the player to stay on the screen even if the player keeps moving up
@smoky pikeThe target position should be independent of the player
camera.transform.position += new Vector3(0, 0.5f * time.DeltaTime, 0);
If you want it to speed up/slow down based on where the player is, we could do that too
I tried that but the movement was still jagged
can you send a video
I will mention again. Maybe this
{
// Move camera up on the Y axis
camera.transform.Translate(Vector3.up * moveSpeed * Time.deltaTime);
// Center the camera on the player on the X axis
Vector3 targetPosition = new Vector3(player.position.x, transform.position.y, transform.position.z);
camera.transform.position = Vector3.Lerp(transform.position, targetPosition, lerpSpeed * Time.deltaTime);
}
have you actually shared your full code yet?
This is the only part of the code involving camera movmenet
The rest doesn't affect the movement of the camera
and yet it's not enough information
we don't even know if it's in Update, FixedUpdate, etc
share your code
I'm not at my laptop right now, I'll send in a bit
There just shouldn't be anything jagged about it
assuming that you're doing everything in Update() and not FixedUpdate()
Yes it's in Update()
camera movement generally should be in LateUpdate
as late as possible - certainly after everything else has moved
It moves independently of everything else, so it's not going to matter in this scenario
the render still happens at the same time no matter what
targetPosition = new Vector3(player.transform.position.x, player.transform.position.y+velocityUp ,-1);
Seems it's moving relative to the player object
so reading the player's position before or after it moves this frame will make a visible difference.
(of course this depends when/how/where the player object moves)
The video shows the problem as the camera moves really fast when the player is at the top of the screen
The video is using that code
what's your actual desired behavior
if you don't want that, why are you basing the movement on the player movement?
(Don't think that uses code I provided maybe mentioned me by mistake)
I need the camera to follow the player like Crossy roads
While the camera is moving up
well if the player is moving fast
the camera will need to move fast to catch it
there's no way around that
Maybe I'm implementing this incorrectly because Crossy roads uses a different algorithm
I'm trying to copy the camera movement but Im not sure
crossy road and doodle jump are two different games
with two completely different camera behaviors
Hey does anyone know how the spherecast works in code? Like how do you make that by scratch?
Lots of applied mathematics
yup, do you know it? Or do you know where I can research it cause I can't find anything online
All of the underlying collider stuff is Physx. The physx code is all written by Nvidia.
Thank you, sweeps would typically work but I am using a mathmatical sphere and not a sphere made of points?
It doesn't look like anything else here talks about sphere casts
mathmatical sphere and not a sphere made of points?
pretty sure these are the same thing
no mine is a vector point and a radius. Not a polygon mesh
What do you need a custom solution for?
I thought that maybe I could use a standard raycast and"inflate" the mesh to get the reverse effect and then extrapolate
I am making a simulation in blender with AI units moving around and their hitboxes are just spheres
yes I am aware, but the code concepts are the same
concepts span farther than programs specific languages
if I can figure out how unity did it, ir unreal even, then I can translate to blender
its ok mate, no worries, ill look somewhere else
thank you for helping
@stark glen unity just calls PhysX engine, you're more likely to find an answer by looking at ECS physics
oh ok ill look into that now thanks! I think my solution will just be shooting like 5 rays to capture the "bounds" of the sphere given the direction that the sphere is moving
That's still going to miss everything in between the rays
and probably way heavier
true, its not a perfect solution but given that 99% of the time these units are smaller than any given mesh faces they can collide with, it will work for now
5 raycasts are more performance than mesh collision detect by far so it will be ok I think
its all about trying to make something that works first and then optimizing it
I appreciate your guy's help!
I find it suspicious that blender doesn't have casting solutions built in
I am working in geometry nodes and they only provide the standard raycast. Any other method needs to be built by hand still
@stark glen why not make the simulation in unity instead?
I am making a tool for blender for a client, it will be an addon for blender so that people can make AI systems for their animated films
since I am mainly a programmer I tend to look at how to make things in unity or unreal and then I transfer the concept to blender
yeah well good luck, i remember an ECS tutorial building a physics system from ground up so that might help
oh yeah that sounds interesting!
Good night everyone! Could someone help me find what could be happening with this light maps? This dots on the wall weren´t supposed to be visible or even baked in the light maps, because they are far from the the point light range, does someone knows any fix for this?
I´ve tested and they are coming from the candle lights for some reason
Sorry, I´ll question there!
For a building menu in my project I need to render a bunch of game object prefabs as images in the UI. What is the best way to go about this?
make a new scene which you use another camera pointing at your objects , write to a texture and use that
RenderTexture
Ok great, thanks
doesn't need to be a new scene btw
it can be same scene if you make the 2nd camera only render a specific layer and set to Depth only
👌
Can someone help me?
You need to clarify on what you're doing
with graphics or something
Is it that hard to understand? I just want a fully interactable Light Tower Generator.
Yes, it is pretty hard to understand when nobody knows what an interactable light tower generator does
Do you even know what's a Light Tower Generator/Light Generator Unit?
alright man good luck
I'm just saying.
alright
Ah, an electrical generator with floodlights attached to it
was that so hard?
you still haven't said what you want it to do
Animations
I made an animation but I want to be able to control it's position with two buttons (in VR).
I just don't know how to code it.
i dont really know how to ask this so i'm just going to shoot my question...
Yes.
Everyone calls it Light Tower Generator.
i have some materials and textures that are created via script, but because they are created in script, they do not show up at all in the heiarchy/project tabs. is there a way i can grab and move them elsewhere? (i tend to do temporary adjustments while in playmode to understand what i am doing.)
@magic ventureI've found the easiest way to do this is to use an interface, like IClickable or something
that way you can do a single raycast, check if the object has IClickable using GetComponent, then run the code you need
easy "Press Use" system
i figured i could just just make the textures outside of script, but i really want to know if this is possible
because like, if you make some game objects in script, they appear in heiarchy. but other stuff such as render texture, or materials, don't pop up anywhere?
Wait what?
I don't get your point.
C# interfaces
I mean that I actually have the whole thing working like buttons and that but I only need to make the pole to extend.
Idk how to make the pole to extend like a real LTU does.
modify the scale of it
By setting up your Animator state machine and setting parameters in code
or that
!learn
🧑🏫 Unity Learn can offer you over 750 hours of free live and on-demand learning content for all levels of experience! Make sure to check it out at https://learn.unity.com/
They have animator tutorials
But there are two problems, the texture tilling and that I just want it to move towards an specific position and after doing so the next section to come up too.
I tried but it doesn't works.
I tried playing the animation backwards but the -1 parameter doesn't works via script only in the editor.
Which is why you need to post code
because I'm pretty sure you can set an animator to backwards speed in code
The point is that I want to make a code to work with it so I can use the same code for other objects instead of using an specific animation.
You haven't posted any code yet
you need to post code if you want help
How am I supposed to post code if I don't know how to start it? That's why I'm asking for help.
I know that I need a variable for the gameobjects but idk how to continue it cuz I want to be able and select as many sections as I want so idk how to make the script that compatible.
You should be in the beginner section.
It's not that of a basic thing, I wanted to ask for the full thing including making an electricity system for it.
It is a basic thing. I asked for code and you have none
I'm not being an asshole, but nobodies going to sit here and program features for your game
You've got to learn at least the basics.
I know the basics for sure.
I just don't know how to implement this of the multiple sections extending thing.
You need to break this up into multiple problems.
1.) Detect if the player is pressing E (or whatever use key) on your generator.
2.) Is generator extended? Play animation backward.
3.) Is generator packed up? Play animation forward.
hey guys, any idea how i can improve my code for a missile to track a player? this is what i have right now
Vector3 dest = _player.position;
Vector3 orig = _missile.position;
Vector3 diff = dest - orig;
_missile.MoveRotation(Quaternion.LookRotation(diff));
_missile.AddRelativeForce(0f, 0f, 55 * Time.deltaTime, ForceMode.VelocityChange);
the missile just keeps overshooting and having to turn around though
also tried implementing a velocity limiter which helps a bit but not much```cs
Vector3 preSpdLim = _missile.velocity;
var spdLim = new Vector3(
SpdLim(preSpdLim.x),
SpdLim(preSpdLim.y),
SpdLim(preSpdLim.z));
_missile.velocity = spdLim;
[...]
private float SpdLim(float spd) => spd >= 0 ? Math.Min(spd, MaxSpd) : Math.Max(spd, MinSpd);
Well, one thi g you should definitely change is get rid of the magic number.
If you want more control over the missile velocity, you would either set it manually, or get the difference between the desired and current velocity and apply that much force, instant of a constant.
what magic number?
(0, 0, 55)
You should use a variable defined elsewhere(probably the inspector?) instead
I'm also a bit sceptical about multiplying it with delta time.
ah ok
Real missiles will never turn around when they miss
and they miss a lot
It would be more realistic to fire a bunch of dumb missiles at the target, where only like 5-10% of them are actually expected to hit
Haven't looked much at your code either, but the missile should be tracking a predicted target at the interception point
rather than following the ass of the aircraft
Real missiles explode if they're about to miss the target.
right
hey its just a game haha
I know, just saying
also its not really supposed to me a "missile", more of a homing projectile
firing at something flying in the air?
because theres this weird restriction in my assignment where i cant have anything resembling current weaponry
e.g. missiles
yeah
it's easier than you think
i can just aim for target.position + (target.velocity * timeToTarget) right?
cool, ill give it a try :)
im not sure how i'd implement that tbh
although i guess i could .GetComponent<TargetHp>() and decrease the target's HP from the missile
real missiles have shrapnel like a grenade, for scenarios like this
its just that the current code detects if the target touches a missile (from Target.cs)
maybe i'll redo that piece of code, i think its worth it lol :p
anyways, thanks!
Hey, I have question about Collider2D.
I have a case when the colliders are not working when objects move fast. I searched on Unity forum, saw that it was issue reported since 2016 (or so) and now I am using 2022.2.20.
I have this video here to show the case: https://www.youtube.com/watch?v=dzwvdDDqYWk
I think you could check the dot product of forward and the direction to the target, and when it gets to 0 or bellow, that would be when you've just passed by the target.
hm..
i was just gonna store the minimum recorded distance to the target
hi I am having trouble getting a gravity working on my player. I am using character controller not rigid body could someone help me in a vc or something maybe or is that not allowed here
and if the current distance is greater than the minimum recorded distance, explode
use SimpleMove
not move
it calculates the gravity automatically
any issues with that logic or should it work?
Yeah, that works too
alr ty!
The very first underline should make it pretty apparent
look at your braces
I did it and it still falls through the floor
Then your floor doesn't have a collider
or your character controller's in-built collider isn't configured properly
or you have a ton of force downwards causing your character to clip through the floor
read what I said
you also shouldn't have a box collider and mesh collider on the same object
should i get rid of one of them and if so which one
get rid of mesh
I doubt that's going to fix the issue
your character controller should also not have a collider
I dont have a collider in it
I watch it fall through when i press play
make sure the floor has a green outline
it starts where i have it but it just falls through the floor and keeps going
why does it have two colliders?
already solved that
while im in the editor or in the actual game
well sort of. Have we actually seen the gizmos for the remaining box collider?
cuz in the editor its red outline
editor
Where is it
why are you using the rect tool?
This is what the box collider gizmo should look like
it's a green wireframe
In the newer versions of unity the gizmos are so fucked
they don't show up half the time
they only show up for me if I disable them, then re-enable all of them
your object scale is 20/1/20 and the box collider size if 10/2.2/10 so it's going to be absolutely massive
200x200
I do not have most of those options
oh
What the proper size should be
whatever size you want
1? because then its the same as the plane
Like I said - whatever you want
If I have a rigid body as a child object, is there a way to have the physics local so I can move the parent around without messing up forces.
This aint how physx works
you can't parent physics bodies
not an easy way, no. Using a separate physics scene is the most robust way.
Sort of like a "snowglobe" concept
no green outline ?
Ah yeah. It will be easy enough to just have copies of the objects mimic the physics objects positions/rotation in local space
no, you should resize the collider
record your player falling through the green collider
please
If it actually is falling through, then you probably screwed up your physics layers
can you also show the inspectors of the "Cylinder" and "Main Camera" objects?
video and pics
The video showed pretty much nothing useful
wait now you';ve checked "is trigger" on your plane's box collider
that will make it not a solid object
uncheck that
open your player in the inspector
and show the character controller collider gizmos
there should be another green mesh around it
there is no green around the player its omly on the box
see in the cylinder screewnshot
the cylinder child is positoned at like 4, 6, 0
it should really be like 0,0,0
so it lines up with the capsule
should it be at wherever my Player is or at 0,0,0
taht sthe same thing
press Z in the editor so you can get your tool handle position at the pivot
rather than center
center is confusing you
is there a built-in method to get a sum of velocity vectors?
thank you
in other words, find magnitude of the velocity vector given a Vector3
just add them
really?
@grim smeltvector.magnitude
thought i had to do some pythagoras theorem stuff
Vector3 has a .magnitude property
ah
thanks
i was gonna start doing the math manually lol
I mean you even had the term correct
all you had to do was start typing it / check the properties 😉
haha
Note that "sum of vectors" and "magnitude of the vector" are two very different things, hence the first answer you got.
ah right
sum of vectors would just be matrix summation right?
If you're that dead-set on doing it yourself, make yourself a little library
or whatever it called
rather than doing it all by hand
no. It's just piecewise addition
its fine, all i wanted was to ask if theres a built-in function
ah ok, ty
Note that Unity's Vector3 has overridden the + operator so you don't have to do that yourself. It's just a + b to add two vectors
or +=
yup
it's worth checking out how they did the override just in case you need to do that to your own structs and stuff
having a problem where the grounded check does not register properly when at the very edge of a platform even though its the same size as the boxcollider
i've had this bug since day 1 and havent been able to fix it
code: https://gdl.space/dovemaxage.c#
size for the boxcollider is 0.9 and the size for the grounded check is also 0.9 if not very slightly bigger
yep, thanks
Well it looks like it's still colliding. Like one pixel.
the grounded check is set very very slightly larger on the x axis on the boxcollider its self so i think this is less of a problem with my code and more of a problem with unity
which is annoying because this is one of the most annoying bugs in the game
maybe there is something wrong with my code? i dunno
How is that a unity issue, you seem to have just said what the issue is and why its inconsistent
im stumped
I'm not sure I understand the problem. If the boxcast(or whatever you're using) is even larger, then of course there would be ground detected.
Unless you intended to say that the ground check is larger than what you're asking it to be.
what you mean not register properly ? what is the issue happening
That image fully looks like the player should be on the ground though
yea but the grounded check isnt detecting it
i have no idea why even though its literally bigger than the collider
Add a debug to draw the resulting box
Ok, so it doesn't detect it
yes
Yep, you just need to debug it.
I dont remember the exact name it's like Gizmos.DrawWireBox?
Nothing about it should be unity's bug.
green lines are the box collider
red is the grounded check
its literally larger than it
How are u making this red area
I'm not even sure what we're looking at.
zoomed out
the thin green lines are the box collider
the grounded check is literally larger than the box collider
or atleast
Well,how are you making sure that they're the same?
box collider size
grounded size
if that's what you were asking
What about scaling?
I see 2 different numbers right there..
yea the box size is larger than the collider
I'm so confused on what the actual issue is
same tbh
IsGrounded is false when it shouldnt be?
Does the object have 1 1 1 scale?
yes
also boxcast moves in a direction each cast idk if u want that or overlapbox instead
And the parent scale?
And all the parents in the hierarchy
it is located on the parent
the player is the parent
I assume you would want overlap box too
its just the script on the player
Does it have scale 1 1 1?
All of the parents and the object itself have the default scale?
Okay. Try debugging the value of the box collider width and the box size variable before drawing the gizmos.
I dont think the box cast would be affected by object scale
That sounds horrible if it's the case
second message is the box size variable
first is the box collider width
the grounded check is larger so why wouldnt it work
Hmm
Idk why we talking about the size of the object lol, something else is definitely the issue
maybe its just a problem with boxcast?
i can try using contactfilter
use overlapbox instead:)
or that
Casts work slightly differently in 2d and 3d so I dont think it's the same issue as 3d would have
Though u can just try overlap box anyways. No reason to really cast the box if it doesnt move
Wait
a possibility also if its inside the collider iirc it doesn't detect it
So the visualizationis correct!!!
Goddamit, you got me thinking that the gizmos sizes don't correspond to the numeric values!
Or do they...
?
that is the difference between 2d and 3d
is it? i barely use 2D tbh. always doing 3D colliders with sprites when I do 2d 😛
ive never used 2d, i just learned it cause 90% of the people here make 2d for some reason
people making 3d don't have time to chat :>
quite the contrary for me, i have all the time because im avoiding implementing netcode for gameobjects
why that specifically?
@lean sail yeah but neither gets the game closer to release lol
my game is relatively simple fortunately so theres a lot of stuff i can skip like most animations. Been coding for like 1 month and i think at this point i pretty much have all the working parts, its multiplayer/level design thats left. Pretty huge tasks but still
UI is a lot simpler than I thought
for simple cases, sure.
I dont understand where people get the patience for level design. Having to add little doodads all over the place is ugh
they don't lol
my patience is that I dont want to work in corporate for the rest of my life
that's why procgen/roguelike is so popular
i'm still sitting in empty area because i dread actually working on that part
so, my missiles work now :D
currently i have a static image that displays on the canvas showing the position of a fired missile
its just a basic arrow like this
how can i rotate it to represent the missile velocity direction?
@grim smelt #💻┃code-beginner . maybe even chatGPT or google, it's not a good idea to ask questions before giving a honest attempt at solving the problem.
yea that one is pretty trivial for this channel, especially since i assume thats 2D
ah ok
i wasnt sure which channel to ask it in lol
huh, maybe im just dumb
im not really sure where to start 😅
quaternions :> everything related to rotation involves them :>
yep, thats definitely going on my list of "ways to rapidly disassemble brain"
just look at the methods it has and it'll be fine
https://docs.unity3d.com/2023.2/Documentation/ScriptReference/Quaternion.html
you dont even really need quaternions for this, im sure euler angles would also be fine
although yea rotations are stored in quaternions
even a 2d rotation?
@lean sail mate
I know that quaternions have a euler angles field lol
that im aware of
but that doesnt mean quaternions and euler angles are the same thing
it's not a field, it's a method to translate euler to a quaternion and back
yes i know that, which is why i said euler angles would also be fine
i think AngleAxis is more appropriate for 2d anyway
btw a field is correct. A field is a variable, method, or property
its just a way of saying a class has it, without really specifying what "it" is
err, i never heard field being used for methods, but i checked it just in case https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/fields
No, a member is what you describe
.eulerAngles is a property (and properties when compiled are just methods)
so i guess the first step would be to convert the absolute Vector3 (velocity) of the object to a Vector2 on-screen (in the current camera)?
not sure how quaternions would help with that
i guess i *could* take the WorldToScreenPoint at two points in time
you want to rotate something, therefore you need to use quaternion.
and then find the angle between the two and set that to the icon rotation angle
why do i want to rotate a vector?
hm thats weird, ive always heard it called a field. maybe its more related to other languages, or just commonly used in place or member
what rotation are u trying to set it to? like is it trying to match the rotation of your missle exactly?
basically, if the missile is travelling to the right (from the camera's perspective) the icon would be rotated 90 degrees right
and if the missile is travelling to the bottom-left in this perspective the icon would be rotated 225 degrees right (or 135 degrees left)
this isnt the direction the missile is pointing though
this is the direction of its velocity vector
so if the missle is pointing up but travelling down, you want to point down?
basically, the orientation of the missile can be ignored
you should be able to just use the velocity then
the only thing that matters is its velocity
so yes
how would RotateTowards help with this?
im not trying to rotate the missile between two orientations or anything
dont think it would
oh
uh i am really forgetting my linear algebra, i think cross product just be fine?
sorry, rotate what?
but why would i need to rotate the rocket
its not like it would change anything, it'd still be travelling in the same direction
you can maybe use LookAt actually
you know what im just gonna make a round/symmetrical icon
so i dont need to worry about directionality
hm, lemme see
this might just be hacky i dont know if this is a proper solution but try
transform.LookAt(transform.position + rb.velocity);
assuming its a rigidbody
u can just ignore the y or z component if u dont want the icon to rotate on those axis
alr, thanks
my dumb brain has no idea what this code is doing but i'll try it out haha
https://docs.unity3d.com/ScriptReference/Transform.LookAt.html
Description
Rotates the transform so the forward vector points at /target/'s current position.
i mean i know what the method does
basically point the image towards the velocity
i just dont get why we're passing it the argument we're passing
yeah ig so
giving it the transform.position as an offset so that the icon can be anywhere on the screen and not pointing at (0, 0, 0) constantly or like (1, 0, 0)
So you can imagine the velocity vector as starting from the middle of the icon
just imagine a line pointing out of the icon, that is the velocity. Your icon should rotate but probably ignore the x, y, or z axis. I dont know anything about 2D so i dont know which axis it is. though thatll be an easy experiment
now since we're transforming a 2D object do i need to do any more WorldToScreenPoints?
nah u shouldnt have needed that at all
ah ok
unless u want your icon to depend on something else
i see
is there a way for me to force limit available ram, like you can with the framerate?
!xyproblem
Asking about your attempted solution rather than your actual problem
but what I am making needs to be able to run on devices with limited ram, wouldn't that then bring the question on how I can test with limited ram?
you can observe the ram usage with profiler, Graphy, you can test on such devices or you can in theory test it on vm with limited mem
alright, thanks
My original unity project had 3 cubes in it. However, when I committed it to github and redownloaded it from github, the unity project no longer had the 3 cubes, and had the following error in the console “[03:11:57] Rebuilding Library because the asset database could not be found”
For context, this was the gitignore file that was used
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
#
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/
[Bb]uilds/
[Ll]ogs/
[Uu]ser[Ss]ettings/
# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/
# Recordings can get excessive in size
/[Rr]ecordings/
# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*
# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*
# Visual Studio cache directory
.vs/
# Gradle cache directory
.gradle/
# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db
# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta
# Unity3D generated file on crash reports
sysinfo.txt
# Builds
*.apk
*.aab
*.unitypackage
*.app
# Crashlytics generated file
crashlytics-build.properties
# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*
You seem to use an old version of the gitignore
Note the first bunch of ignores have changed
maybe that is the issue
Where were those files located anyway?
I believe I used that version of gitignore too before, but Im pretty sure there was still an error
We're the cubes in a scene?
Did you save the scene before commiting?
that is not an error
that is correct behavior
assets shouldve been pushed to git though
but your cubes yes you probably just didnt save changes
I saved the changes in unity, and commited and pushed the changes
Is that a screenshot from the past?😅
can you find the scene file in the commit
I took that screen shot a few seconds ago
Can you please share what the folder path was where your cubes were located
can you find the scene file in the commit
So we can actually confirm it's not a gitignore issue
So you recreated the scene now? Is that correct?
How do I determine this?
can you find the scene file in the commit?
I assume it would be your scene file
u can have 2 versions of the project on your pc. Probably just pulled the git one to a different folder
at least i assume thats what they did, thats what i did to test how it works in my first week
Thats the scene I am trying to commit to github. I am trying to commit a scene with 3 cubes in it
🤦
Ok, then what's the problem? How do you know that it's not being committed?
can you find the scene file in the commit?
Find the scene file
I redownloaded the project from github onto another computer and the 3 cubes weren't in the project
unity netcode client host connecting only in the same computer and not in other devices
damn i love helping people
Well, did you open the correct scene? And yes, confirm that the scene has been committed in the scene history.
Hello everyone, please can someone help to achieve these looping effect❓
love when they respond to the one question that wont get anywhere cause we already know the answer too
The problem is that people ask 10 useless questions to a problem that is incredibly simple to debug
The problem is that the problem was not explained properly.
Wrong gitignore? Check if the folder was related to the ignored files that were caused.
Not the problem? Go make a change to the scene and check if git picks that
it was explained pretty clearly to me at least
It does? You simply didn't save
Oh wait I realized I didn't open the correct scene. It was there all along. I'm such an idiot
need help
Well, it was not obvious wether they confirmed anything. Which their reply proves...
The question was pretty clear, but the help certainly wasn't
Which is pretty rude to say, but it's pretty easy to debug the issue, and it's straight up ignored because of the cluster of messages
What have u tried so far?
The git question is also not a code question
@river tangle screenwrap or platforms?
Tried to use two cameras for that, but I don't know if i need to instantiate the object from one side to another, or to move the map, then switch camera.. I 😵💫
#archived-shaders this is not a code question
ok sorry, i didnt know that channel exists, imma just copy paste this question tho
screenwrap
@river tangle it's a common thing with endless runners so it's easier to search for that than to explain
I've search for that already, they talk of parallax, but I don't want that, I want a looping level like for New Super Mario Bros DS when you play in versus mode.
can we use netcode to connect devices that are not in the same local network?
parallax is completely unrelated
This is the video I sent 👆
#archived-networking
But to answer your question, you'd need to use a relay or port forward the involved parties(not guaranteed to work)
not recommended? use miror pun2 then?
what technique should I use❓
literally anything that is related.
either "teleport" player or chunks of map, nothing that should be hard to google. maybe you'll even find a better way there.
Photon works through a relay afaik. That's why it's not entirely free(the free tier is useless in production). I don't think mirror provides a relay service by default, so you'll need to use a third party services for that. Unity provides a relay service that you can integrate with Netcode easily iirc.
can i dm you?
Nope. If you have further questions, move to #archived-networking
ok, thanks
Each building, item, etc. has different components
To load/save games with different type of items/buildings, which approach do you prefer?
One data component to pack all required data in all components of that gameobject
Each component handles data by itself
Also, it is suitable to use component based approach to get/store data of components for each item, building, etc.?
public class ModuleData
{
public Dictionary<Type, IComponentData> Components;
public T GetComponent<T>() where T : class, IComponentData, new()
{
if (Components.TryGetValue(typeof(T), out var componentData))
{
return componentData as T;
}
componentData = new T();
Components.Add(typeof(T), componentData);
return (T)componentData;
}
}
public interface IComponentData
{
}
public class ModuleComponentData1 : IComponentData
{
public int Data;
public String Id;
}
public class ModuleComponentData2 : IComponentData
{
public float3 Rotation;
public float3 Pos;
}
public class ModuleComponent1 : MonoBehaviour, IDataPersistence
{
public void LoadData(WorldPersistentData data)
{
var componentData = data.Modules[gameObject.GetInstanceID()].GetComponent<ModuleComponentData1>();
//componentData.Data
//componentData.Id
}
public void SaveData(WorldPersistentData data)
{
var componentData = data.Modules[gameObject.GetInstanceID()].GetComponent<ModuleComponentData1>();
componentData.Data = 21;
componentData.Id = "Hello";
}
}
building data
component1 (data1)
component2 (data2)
component3 (data3)
you might have to specify a little more what you mean "component based approach"
dont understand why you need all that in the ModuleComponent1
wouldnt it be simpler to pass serialization context to ?
any good places to go to?
Shameless self promoting, but I made a save system example: https://github.com/PillowCoding/UnityExamples-SaveSystem
Might be useful, who knows. It collects save data from components that are registered to save basically.
well for one, #💻┃code-beginner since u know.. beginner. and !learn
🧑🏫 Unity Learn can offer you over 750 hours of free live and on-demand learning content for all levels of experience! Make sure to check it out at https://learn.unity.com/
are there any, external, advanced networking tutorials?
i looked through this quickly before, but i had a question. Wouldnt this be flawed if an object wasnt loaded/registered but had save data previously? From what I saw it would just keep rewriting the file
Yes, it's one of the mentioned issues
I assume whatever loads and saves exists when you call this manager
I suppose it's not as bad when you consider this would be a problem either way, and you should use proper managers
I mean its not bad, I think its very usable for the current game state like time of day/inventory/character equipment
A separate file for items that need to save at irregular times is probably ideal on top of that
It definitely is fixable though, I just didn't bother doing so since this was more meant as an example and not a solution
also are you using prefabs?
Exactly, you can also make a seperate file that exists no matter what, and fetch your data at a later point there.
I could add that to the readme
i was actually looking at yours when thinking of how to make my save system. I realized my saving would be very different though as im pretty much only saving what levels the user beat and what hat they have on lol
So mine just saves 1 file per class that needs it, and the key is just
string Key => GetType().Name; to get the name of the file
thanks for making that example still
oh ok thanks
I mean I can put all data of different components in one place and then save/load them.
For example in runtime, a building with type Building1 has three components, each component has its own runtime data. I can create a specific component to handle data.
The second approach I said component based approach, I mean I can create a dictionary with key gameobject instance and value a list of component data.
I use the component thing and it works fine, especially when throwing together weapons with different modifications
sounds overengineered in the wrong places
It does not matter. I want to save/load runtime gameobjects with different components on
yeah, break it down into SO data/GUIDs and paste it all together
oh, if it's runtime then im not too sure
if you are serializing a game object hierarchy you have to care about
- root it
- internal component id
- prefab link id
the data could be just a game object serialization context, where for each serialized component you create a dictionary of string/string in case of json, and pass it to the serialization callbacks,
but the ids, what to pass, should be handled externally by your save system
public void SaveData(ComponentSerializationContext data)
{
data[nameof(Data)] = 21;
data[nameof(Name)] = "Hello";
}
here you dont need pods, you can straight up write into container
my first time messing around with assembly definitions, and I'm getting a bunch of errors in visual studio now, but none in the unity console... Am I doing something wrong?
mapping/resolving all that will be done by system, references also will be converted by it
and post load linking
What are you talking about?
I did not get it
It is runtime data
so? you dont have references on runtime?
Prefabs? serialization context?!
My VSC can break a bit when I add asmdefs. Try restatting your VS and Unity completely
dramatic, but what exactly am i failing to convey?
Try regenerating project files. Unity should move some of the code to new assemblies.
Okay I shall, then I'll report back thanks
Do the regen proj files
okay I'll also try this at the same time then, thanks
You want to resolve property names?
componentData.Data = 21;
Instead,
componentData[nameof(Data)] = 21;
I am OK with the first one
first one requires boilerplate, which does exactly the same and has the same problems
I can't seem to figure out how to do this, and google isn't pulling anything up... How would I do that?
because when you will be serializing your componentData object your serializer will still map the property to a string
with all the typical problems from that, like backwards compatibility of data
It's in External Tools settings.
thanks!
ok yup regenerating the project files fixed it, thanks a ton!
but in the second case you can add specific cases for upgrades
void Load(data)
{
if(data.version < 4)
this.SomeInt = data["SomeInt"];
else
this.SomeInt = data["DifferentNameInt"];
}
well you can use attributes and whatnot for your pods but you are still creating boilerplate
Make sure that your assembly definition has a reference to the assembly definition of whatever you use.
It might be possible your editor breaks and does not have syntax highlighting. You need to make sure "editor" is enabled in the assembly definition.
This will properly generate a csproj then.
I get your concern.Backward compatibility,etc.
You say it is better to save data as a dictionary like <string,object>
it is simpler, solves the issue, is fast as it doesnt involve reflection
(PropertyName, Value)
if you delegate this job to serializer lib, it will reflect your pod
with a dict it will just directly dump its values into the file
Only problem with this is boxing which will definitely impact performance.
I hate to say it, but maybe you need an ExpandoObject for this?
It has to keep types as well, so the bigger size
you can even use some forward serializer like odin if you dont care for human readability
can be complicated but if you later decide to swap serializer, you dont need to change anything else in the codebase
all the Save/Load will still use the same SerializationContext or whatever api
but if you want to rely on serializer specific attributes in your pods, you are in for a massive refactoring
ExpandoObject ? Definitely no
and for component based? What is your opinion dude? Do you agree?
IDK how boxing works with ExpandoObject but if it's prevented then yes, it does work as an alternative
That said, it's terrible to use
component based what?
But still better if you don't want to create a wrapper
For each gameobject with different components.
public void LoadData(WorldPersistentData data)
{
var componentData = data.Modules[gameObject.GetInstanceID()].GetComponent<ModuleComponentData1>(); // here
}
public void SaveData(WorldPersistentData data)
{
var componentData = data.Modules[gameObject.GetInstanceID()].GetComponent<ModuleComponentData1>(); // here
}
Keep data for each component separately
i dont understand why do you need this
Because maybe different components have same property name in your approach!
im bad at explaining
class GameObjectSerializationContext
{
public int id;
public List<ComponentSerializationContext> components = new();
}
class ComponentSerializationContext
{
public int localId;
public Type type;
public Dictionary<string,string> data;
}
class SomeComp : MonoBleghvior
{
public Save(ComponentSerializationContext ctx) ..
public Load(ComponentSerializationContext ctx) ..
}
which ComponentSerializationContext to feed into Save() will be handled by SaveSystem
I should say I understand your concern. It is completely right.
In my approach (strict property name), changing property name is really hard (backward compatibility)
GetInstanceID is not the same between editor sessions. Do you expect it to fetch the data after your editor has restarted? Because that won't work.
You need to explicitly define an id here
that approach should be multi phased btw for reference resolution
because on load , first all the gameObject/components should be constructed
For example, in my save system I want a unique key: https://github.com/PillowCoding/UnityExamples-SaveSystem/blob/main/src/SaveSystemExample/Assets/Runtime/Scripts/SaveSystem/ISaveable.cs
So that's a way to do this
then you do another pass that converts serialized references between them into actual references, and invoke the Load second time with special flag
I get it. my way was dictionary to keep components. In your way, it is List<ComponentSerializationContext>.
Perfect, thanks
just got this warning, is it anything to be concerned about?
It is runtime, so GetInstanceId is OK.
It's unique in the runtime context, so it makes sense to use it here
The code above was raw I know it was wrong, you are right.
It becomes useless if it's more than that
to map serialized references within a single session between clients
The keys are guid of that element, not instance id.
I have guid for each asset.
HI everyone, I was wondering if anyone could see anything wrong with some code:
private IEnumerator Animate()
{
// Set All Points To Invisable
foreach (CosmeticBall ball in _cosmeticBalls) ball.SetOpacity(0);
// Iterate Over points lighting up the first point
float timeElapsed = 0;
while (timeElapsed < PropagationDuration + TrailLength)
{
int points = _pointObjects.Count;
for (int i = 0; i < points; i++)
{
float weight = Mathf.InverseLerp(0, points, i);
float x = timeElapsed - (PropagationDuration * weight);
_cosmeticBalls[i].SetOpacity((x) switch
{
{ } value when (value < 0) => 0,
_ => Mathf.Lerp(FadeAlpha, 1f, EvaluateCustomWeibull(x * (1f / TrailLength)))
});
}
timeElapsed += Time.deltaTime;
yield return null;
}
}
This seems code is meant to take in a trajectory of of a ball and then slowly make it opaque as if it was moving down the trajectory with a semi transparent tail. This seems to work completely fine on my PC but my team is saying that the trajectory lights up imidiatly for them. This has been tested on 4 different PC's including my own, and only mine seems to work. Is there a reason that coutines would behave differently between devices? And specifically is there something in this code that would cause that? To me this seems pretty straight forward and I'm not doing anything overly complicated so I wouldn't have though so.
the code will run the same on each pc. Its stuff like framerate where variations start to occur.
Also maybe u have a SerializeField value set to be something u didnt push
some assets in a folder named Temp,
this ```cs
(x) switch
{
in the lambda can be unsopported on their installs if some language features werent enabled but you would get errors
I'd think so too, but there doesn't seem to be any errors in the console and the ball that is being rendered seems to still display, other then that I can't see what else could be unreferenced. The frame also seems to work fine on the other machines too.
On your pc, try pulling the project to a separate location and run it from there
add asserts/logs for every variable and push, ask to give you logs back
I'll give that a try, see if I get the error still
that way none of your current project settings are used
Yes, I know it but I do not need they are unique in editor and runtime and both have same ids.
No, I just wanted to save gameobjects and because they are stored in a dictionary, just unique id in runtime will be enough (dictionary key).
I have an additional unique id (for each asset) and save them as well.
@earnest gazelle Save yourself a lot of grief and agravation
https://assetstore.unity.com/packages/tools/utilities/save-for-unity-core-242812
(shameless plug for own asset)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pathfinding;
using Unity.VisualScripting;
public class EnemyMovement : MonoBehaviour
{
public Transform target;
public float speed = 10f;
public float nextWaypointDistance = 3f;
Path path;
Rigidbody2D rb;
Seeker seeker;
int currentWayPoint = 0;
bool reachedEndOfPath = false;
void Start()
{
foreach (Transform enemy in transform)
{
seeker = enemy.GetComponent<Seeker>();
rb = enemy.GetComponent<Rigidbody2D>();
if (!rb)
{
rb = enemy.gameObject.AddComponent<Rigidbody2D>();
//rb.collisionDetectionMode = CollisionDetectionMode2D.Continuous;
rb.gravityScale = 0f;
rb.freezeRotation = true;
}
if (!seeker)
{
seeker = enemy.gameObject.AddComponent<Seeker>();
}
seeker.StartPath(rb.position, target.position, OnPathComplete);
}
}
void OnPathComplete(Path p)
{
if (!p.error)
{
path = p;
currentWayPoint = 0;
}
}
void FixedUpdate()
{
if (path == null)
return;
if (currentWayPoint >= path.vectorPath.Count)
{
reachedEndOfPath = true;
return;
}
else
{
reachedEndOfPath = false;
}
Vector2 direction = ((Vector2)path.vectorPath[currentWayPoint] - rb.position).normalized;
Vector2 force = direction * speed * Time.deltaTime;
rb.AddForce(force);
float distance = Vector2.Distance(rb.position, path.vectorPath[currentWayPoint]);
if (distance < nextWaypointDistance)
{
currentWayPoint++;
}
}
}
can someone tell me why my enemy isnt following the player i have added the correct
and it doesnt seem to work
@chilly beacon wait for p.IsDone()
wait its a callback nvm
log p.CompleteState
remove deltaTime from force
but its in fixed update
o kwait
removed fixed delta
no change the enemy doesnt move
sufficient force value?
wdym?
crank it up
changed the speedto 100f
still no change
the enemy doesnt move
alright, do you know how to use the debugger?
i have dont anything on the pathfinder a* component
no graphs
is there any friction?
if not setting velocity maybe better....when reach the point then set the velocity to zero and set a new 2d velocity vector
idk how i would make the graph work since my map is generated randomly
Astar.Scan
in code
when you done generating the map
first create the graph in editor
doesnt matter if its empty
then call AstarPath.active.Scan(); at runtime
in the map gen editor?
but how
and you dont know where your generation ends?
i dont know what you should do to make it work with 2d
setup a test case in editor
learn how it works with tilemaps
hm
make it work on a separate simple test case first, then transfer that to actual game code
ok
my question is can the enemy follow the player without a graph
i mean the graph is bascally there for a guide that this places are not where the enemy can walkthrough
right?
ooo
yes enemy can follow the player without a graph, but you wont be using path
just direct movement with transform
My game is voxel based. I think for voxel part, it is more appropriate to store them by known property fields because the voxel world size is huge around 400,400,400 but for other parts storing them as property name, object is OK
i dont understand
if its a voxel you should only store position + voxel type int, and it should probably be chunked, and SOA
It has other properties as well, like level (for liquids), etc.
It is chunk based, yes and 1d array voxels (it is 3d originally)
SOA?
Because we use MessagePack lib to serialize/deserialize data, in MessagePack you can serialize data by name or key id
My colleague says use key id for each property, so it does not depend on property name
[MessagePackObject]
public class PersistentData
{
[Key(0)] public int Field1;
[Key(1)] public float Field2;
}
yeah nah
public class Chunk
{
public int[] type;
public int[] waterLevel;
public float[] damage;
}
No, it is
NativeArray<Voxel>
Voxel is struct
What is your opinion?
use keys instead of names
It is another problem 🙂
My question is about the prior argument about backward compatibility
if a property name changes
nah its still the same, for serialization you will get massive gains if you dont have to serialize each voxel separately
I say if I serialize/deseirliaze them as key ids, it is solved
you directly writing each property as a massive array
which means that if you use any library that resolves prop types and has abstractions you will be saving cycles because you just dont resolve anything you are directly writing arrays in place
Use AOS or SOA should be depended by the use case
For those data that needed to be used at the same time i will group them into a struct
yes
yes, if they have been used in one routine, it is better to keep them together
My problem assign keys or names?
[Key(0)] public int Field1;
[Key("field1")] public int Field1;
and because it has added an abstract layer to serialize/deseriliaze data, saving data as <propertyName,object> is logical still?
with attributes you can solve any backwards compatibility issue, just create new ones, slap them all over
but it defeats the purpose of what i was proposing earlier
@ashen yoke so i added the
asther scan on my gen code
and i also changed up the enemy script a little bit
but it still doesnt work the enemy doesnt move
no reaction from the red buddy
Hi all, Screen.dpi returns a float of the screen's DPI (as you'd expect), but according to the Unity docs, on android devices it returns "densityDpi which is a logical bucket that contains a range of DPI values". What type is a logical bucket? An array? A list? I don't have an android device to test on, and have no clue what type this returns.
if you click on the thing that says this forum thread
then click on the hyperlinked densityDpi
you'll find that
Hey, someone knows why it s blur?
Looks like you're using the legacy Dropdown component
Are you using any TextMeshPro components?
legacy
You'll want to use TextMeshPro. The legacy Text components behave very poorly when scaled up.
If you've written any code that works with the dropdown, it'll need to be changed to work with the TextMeshPro dropdown
it's a separate component
Ah great, thanks v much. Seems an unhelpful way of doing it, but hey
no, because Text is the legacy text component
TMP_Text is the type for referring to TextMeshPro text elements. You will probably want TMP_Dropdown here, though, since that's the component that runs the dropdown
both of these are namespaced under TMPro
ok i try something
@heady iris
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class TranslateText : MonoBehaviour
{
//refs
private TextMeshPro textZone;
//const
[SerializeField] private string textName = "None";
private void Awake()
{
textZone = GetComponent<TextMeshPro>();
}
public void ChangeText(LangagesManager _langagesManager)
{
textZone.text = _langagesManager.GetText(textName);
}
}
This is not how you should use a dropdown. You need to configure it with a list of choices.
that first for a textMeshPro
this wasn't doing this before, anyone have any ideas why?????
(Click the image for expand)
where is the code question
im, sorry, where should I ask this then???
How do you guys remove lag from first prefab instantiation
There shouldn't be any
Strangely it does
Use the profiler to see why
likely not a concern then
ye
I'm triyng to use the Oculus VR lipsyinc plugin for Unity on a WEBGL build but it doesnt work.
Can somebody please help me figuring out why? It worked fine in the editor.
that could be the reason, I didnt tought about it 😐
Hello, How to move a UI element placed next to a Text, as the text expands? like there are more characters being added into that text and it overlaps the UI element next to it
Don't cross-post. This is a #📲┃ui-ux question, not a code one.
indeed: you can solve this with no code.
I have tried, that's why I'm asking it in code channels..
Doesn't work*
If y'all know a non-coding way, I'd be grateful
Watch me come back here because there won't be a non-coding solution
?
Hi! Does anyone know why I can't unsubscribe this event from the Unity EventBus class that handles visual scripting events? The 'OnEventRecived' keeps getting called even if I destroy the object the script is attached to. Thank you
protected delegate void OnEventRecivedDelegate(string id);
protected OnEventRecivedDelegate EventRecived;
public override void Start()
{
EventBus.Register<string>(EventsType.EventRaised, id=> EventRecived(id));
EventRecived = new OnEventRecivedDelegate((id) => OnEventRecived(id));
}
public override void OnDestroy()
{
EventBus.Unregister(EventsType.EventRaised, EventRecived);
}
Because you're passing an anonymous delegate
Subscribing/unsubscribing work by reference so you can't unsubscribe something that is subscribed as an anonymous delegate, because the compiler has no clue it's related to anything since it's not bound to the same reference.
You need to pass an actual method because that will be the same reference.
register it like this:
EventRecived = (id) => OnEventRecived(id);
EventBus.Register<string>(EventsType.EventRaised, EventRecived);
then unsubscribing will work properly because you will have subscribed and unsubscribed the same delegate
Pretty sure you can just do this too:
EventBus.Register<string>(EventsType.EventRaised, OnEventRecived));
EventBus.Unregister(EventsType.EventRaised, OnEventRecived);```
your lambda isn't doing anything in particular so you might as well just directly register your method
Even if you store the delegate in a variable?
I'd expect it to be the same reference...
No, then it's the same reference