#💻┃code-beginner
1 messages · Page 364 of 1
it tried and it worked in the past
but this time, it doesn't
does the renderer have several materials?
{
spawnedObjects = new GameObject[numberToSpawn];
for(int i = 0; i < numberToSpawn; i++)
{
spawnedObjects[i] = Instantiate(
objectToSpawn,
GetRandomPosition(spawnRange),
Quaternion.identity
);
SetAnimation(spawnedObjects[i], clipsData);
}
}
private void SetAnimation(GameObject spawnedObject, ClipsData clipsData)
{
Material animationMaterial = spawnedObject.GetComponent<MeshRenderer>().material;
ClipData clipData = clipsData.clipsData[Random.Range(0, clipsData.clipsData.Length)];
animationMaterial.SetFloat("ClipStart", clipData.clipStart);
animationMaterial.SetFloat("ClipEnd", clipData.clipEnd);
animationMaterial.SetFloat("AnimationTimeOffset", Random.Range(clipData.clipStart, clipData.clipEnd));
}``` . is there any problem ?
no there is only 1
what's the problem, is animationMaterial null?
no, there aren't errors and warnings
but there isn't material that changed when the game start
but all materials are (instance)
should every farmer be different?
yeah
then just to make sure, do ClipStart and ClipEnd change at all when you start the game?
Might be worth Serializing your AnimationTimeOffset in the shader (make it an exposed property) and then pause the game and have a look on each instance of the character to see if it's offsetting properly?
Why dosent the game object show in the Inspector?
because you have a compile error
Because there is an error in the script
you see red, and you think nothing of it?
Ik why its red but i didnt think it had something about the gameobject
the constructor u used is wrong
Unity can't do anything with your code until it can compile it.
there is not Vector3(Vector3 v3)
ANY compile errors will stop the inspectors updating
It can't just ignore the error and try to compile the rest
'```
void Start()
{
LoadLevels(0);
Respawn();
}
void LoadLevels(int id)
{
GameObject Level=Resources.Load("Levels/Level"+id.ToString()).GameObject();
Instantiate(Level,Level.transform);
} ```
When i start the Game there are two Levels0 in the scene, is Instantiate() running twice?
you have the script on multiple objects then
can anyone help me when I use a .blend file in unity it does not give all collers but only white and black what do I need to do to fix it ?
I had the script on the GameManager object twice thank you so much
i would never have though of that lol
Instead of using the .blend you should open it up in blender and export it as FBX
https://all3dp.com/2/blender-to-unity-how-to-import-blender-models-in-unity/
You'll have more control over what gets exported, and be able to adjust it so it uses the proper axis orientation
it doesn't work it is till white
On the import, you can click "Extract Materials" and choose a location to put them in the project, then you can apply those materials to the mesh
Why does the rotation Scale things when they are a child? of an empty?
Because the root object isn't uniform scale
Oh. Is there an aviable sulotion?
it has collor but now I get dis eror
Make the root object uniform scale
Hi guys, I have been trying to program the player to slide using animation curves, and it did not go the way I expected to go. When I am sliding here, my velocity drops down to a very low value instead of staying at a higher value, even if I change the graph of the animation curve. Here is my code:
SpeedDown(slideRate);
speedDuringSliding = slideCurve.Evaluate(deccelerationProgress) * initialHorizontalSpeed; //Multiply the initial horizontal speed to start sliding at the current velocity
rb.velocityX = speedDuringSliding * direction;
private void SpeedDown(float rate = 1) {
deccelerationProgress = Mathf.MoveTowards(deccelerationProgress, 0, Time.deltaTime * rate);
}
```
Thanks!
is there a problem with the way I am coding this or is there something else at play here?
So, for one thing, you are moving from right to left on the curve. Is that what you wanted? Also, the x value is from 0 to 1, so maybe it is just very quick?
is it possible to access a script from another scene and use variables from it?
If the scene is loaded, yes, if not then no
yikes okay, so creating a slider to change a variable used in another scene is a real pain then?
It's very simple when you understand references and how to manage them in Unity
If the scene is loaded (like additively or in ddol) it is very simple
If it is not loaded, then it simply does not exist of course
yes, but I have decided to move from left to right which is why I have made it go from 1 to 0. It doesn't really make a difference if I change it.
0 is left. Right is 1
oh yes sorry. But my point still stands.
But yeah, hard to say. Maybe it is going very quick, was my suggestion
okay ill give it a go
I have changed the value of rate, but for some reason, the speed is still dropping down way too fast
It's hard to even know the problem from just what I've heard honestly. Try debugging the x value and the return of evaluate
ok so I have debugged the deccelerationProgress value and the x velocity, and the result was that as the deccelerationProgress drops down, the x velocity becomes 0 before deccelerationProgress even reaches 0
the curve that is being used here is a linear curve, so it doesn't make sense something like this is happening
I have a similar function that uses the same code that accelerates, and this one works as intended
!vs
If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
private void ApplyExplosionForce(Vector3 explosionPosition)
{
Collider[] colliders = Physics.OverlapSphere(explosionPosition, explosionRadius);
foreach (Collider hit in colliders)
{
if (hit.CompareTag("Floor"))
{
Rigidbody rb = hit.GetComponent<Rigidbody>();
if (rb != null)
{
rb.AddExplosionForce(explosionForce, explosionPosition, explosionRadius, upwardsModifier, ForceMode.Impulse);
}
}
}
}
I have an explosion force which im putting on a navmesh enemy, once I apply the force the navmesh just keeps moving back and never stops to come target me again, how would i make it so that the navmesh is pushed back by the explosion force then targets me again when it stops moving or the force is done
Shouldnt this Rotate the object?
guys ima misspell continiueue
this rotates it by 0 degrees on each axis
What are you expecting it to rotate by
Lol
I thougth it sat the rotation to 0 on all axis....
Read the documentation to find out what functions do.
I do
transform.rotation = Quaternion.Euler(0,0,0)
could anyone help me with my navmesh problem?
maybe. what is the problem tho?
here
alright so you're mixing Navmesh Agent with rigidbody , you're going to have to show the complete script
So far is not looking good, since you want to disable the navmesh agent while doing the "push back"
thats the complete script
send it via link 🔽
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 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.
oh
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
yeah its the script which is attached to the bullet
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class Enemy : MonoBehaviour
{
[Header("Enemy Settings")]
public int moveSpeed = 4;
public int minDist = 5;
public int maxHealth = 30;
public float lookRadius = 10f;
public Transform target;
public NavMeshAgent agent;
private bool isPushed = false;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
agent = GetComponent<NavMeshAgent>();
}
void Update()
{
if (!isPushed)
{
float distance = Vector3.Distance(target.position, transform.position);
}
}
void OnDrawGizmosSelected()
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, lookRadius);
}
public void TakeDamage(int damage)
{
maxHealth -= damage;
if (maxHealth <= 0)
{
Destroy(gameObject);
}
}
}
ok well lets start with the biggest problem, nowhere are you actually disabling the navmesh agent , not even sure how the addforce worked in the first place
You want to
-DisableNavmesh agent
-maybe go from Kinematic RB to Dynamic
-Add Force
-After certain time or distance, Turn back to kinematic, and turn navmesh agent, assign new destination
also where is the SetDestination here?
Btw the bullet thing can just be
if (collider.TryGetComponent(out Enemy enemy))
{
enemy.TakeDamage(15);
InstantiateBloodEffects(collider.transform.position);
}```
I'm trying to create a gravity switcher mechanic and I'm failing to use quaternions/rotations to reorient and remap player input to handle movement.
Would someone hop in 5min call so I can show current state and ask questions?
Ah okay
very unlikely you get someone on a call
Please don't crosspost. Pick one channel and stick to it, instead of asking everywhere.
It's unlikely people will jump in a call with you, but if you post your code and maybe some video and explain the issue, people will help to the extent they can
So would I have to detect the bullet in the enemy script?
Then disable the navmesh
ideally you put the pushback as a method in the enemy yes
simply call that method when the bullet thingy hits enemy
ya, why spend 5 min showing just (1) person ur problem..
rather than spending 5 minutes.. to type up a solid summary of the problem, with links to !code, screenshots, and videos
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 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.
then many many people have a chance to pop in and help ya
ah okay ill give it a try
thingy needs to be a mock-up component 😄
what does going from kinematic to dynamic do?
haha yeah I used the technical terms my wifes' used in the past lol
kinematic doesn't respect collisions/physics
It will react to forces
You dont want a dynamic rigidbody on a navmesh agent
it helps not fight it out with navmesh agent
they both override the transforms by setting it
thingy-ma-bob, ma-jig, do-dad, whatcha-ma-call-it,
ah i see
it is acceptable for certain use cases, if you lock all the constraints though, to keep it dynamic,
its a cheap way to get Navmesh agents to interact with Rigidbodies around it
I had doors that were physics based on a hinge, and navagent would pass through, with a dynamic rigidbody and constraints locked, the navmesh agent can "push" the door
although this can be cleaner and easy to solve with Physics queries/casts
i use this setup for my agents to push dynamic props out of hte way
i don't modify the rigidbody ofc
it is acceptable for certain use cases
oh, ok i see u agree
yeah tbh as long as the constraints are locked, its not an issue
a dynamic rigidbody without it though will be fighting for the Transform component
You ever try to move navmesh agent manually with the arrows? doesn't happen, it just goes back where it was last before you moved it manually
hence to teleport it you have to do the same thing you do with Character Controller (disable-move-enable)
or use navMeshAgent.Warp
Reduce the minimum movement distance on the CharacterController
The default is a bit too high.
I'm not sure if there's any problem with setting it to 0
I guess it saves work if your controller is getting extremely tiny move commands
like from a smoothed input that takes a long time to actually hit zero
is that not the default ?
Just wrote me a little Mouse Follow script..
Made it work as 2d plane, 3d plane, and raycast into world space, (+normals)
awesome little addition to my snippet collection..
question: has there been any new addition to inspector stuff maybe attribute to make it soo only some booleans appear dependent on other booleans?
soo for example.. when 2d is false then options like the use normal would be visible..
you need a custom inspector
no way built in rn
that´s a pokémon.
not too performance heavy would it?
nahh
okay good.. i can do that 👍
If possible try using UIToolkit but the old GUI works just fine
i'll look into that. i havent tried it yet
i was coding editors the other day 🙂
feeling a lot more comfortable with them now
i agree... it took me WAY too long to realize I could just make a function to do all the tedious stuff
hmm its not animating
my last editor script had dozens and dozens of GUILayout.Begin, .End, etc
then i realized if i used a function instead.. it cleans it up alot
oohhhh bb.. very nice! 🙂
i havent done anything with a scrollbar yet
unless you count this..
I was trying to add more custom stuff in the table entry but was a pain 😅
omg twitchcity
i cant figure out how to solve the issue..
the component by itself.. doesn't do it.. b/c the scroll is dependent on how large that (1) component is
oh yeah this is inspector, so its a bit different
It's beautiful. Just leave it
mine isn't a custom inspector, but a custom window
if u have them expanded.. the scrollbar makes it jitter
OHH!
i havent done any of those either
are you sure thats from the editor script and not your Unity
Overlays?
just poking atthat right now, actually
like w/e these are called is that that?
yeah I wass trying to find out but wasnt sure what to add in the first place
yesh!
ohh i was thinking this
with the new Unity6 utilizing them soo much
i want to get into them myself
looks fun
can you believe thats where probuilder is now
that's also an overlay
its about time
ive always disliked probuilders cartoony window 😅
Hey can you guys help me with instantiate
Maybe
wont know til we know
I want to delay the process
it was nice to have everything in one window, takes a bit to get used to doing everything by right click menu now
Coroutine or a timer in update
Am using visual scripting
Well, then I guess timer in update. No idea what vs has
wrong channel then #763499475641172029
it is.. b/c the image is scaled unless it has room... soo 400 pixels wide for example.. it can't get any bigger than that.. but it can be scaled smaller..
soo in that one specific circumstance.. the scrollbar pops up.. (makes the image scale down) and then it fits... soo the scrollbar disappears.. (now the image can scale back up.. so it does..) then the window is too small so the scrollbar pops back up..
and it cycles.. 😄
Ohhh so the image is causing it?
might have to nest it into something else
my only other alternative (that i can think of) is to just make it a fixed size
oh thats a good idea
i'll try later when i make my rotation back to editor stuff lol
UItoolkit also has interesting functionalities that are css-like
flexbox and all that
if (spawnScript.logoTexture != null)
{
float inspectorWidth = EditorGUIUtility.currentViewWidth;
float logoWidth = Mathf.Min(inspectorWidth, MaxLogoWidth);
float aspectRatio = (float)spawnScript.logoTexture.height / spawnScript.logoTexture.width;
float logoHeight = logoWidth * aspectRatio;
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label(spawnScript.logoTexture, GUILayout.Width(logoWidth), GUILayout.Height(logoHeight));
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.Space(10);
}```
im not well versed in the editor stuff...
but im adding to me list of things i know about as i go
imagine being a web dev and having enough patience to use UIToolkit
ohh lord... css makes my skin crawl
isn't there something else instead of a Label ?
lmao
Well no one is on vs
css is neat. Although I almos always use a utility like Bootstrap or Tailwind
So should I also switch to coding
it be like that sometimes ¯_(ツ)_/¯
Definitely
if you know visual scripting, the logic is the same
coding makes you better at vs
you're just typing it instead of graphing it
Honestly yes. It's actually easier to learn real C# code because you have a lot more resources to find answers. Bolt is Unity-specific, but C# is used everywhere. A lot bigger knowledge base to draw from
yup, visual coding is just little snippets of code contained in a node..
Ohh
if u know which nodes connect. you'll be just as good coding it by hand
I have started learning c#
Visual Scripting is kind of a "noob trap". It feels easier to learn, but since it's so specific in scope it's actually harder to find good information about it
True
could someone help, i tried doing this but it keeps saying that it cant add the score because AddScore protection level is too high to access
That looked so easy when I first tried
vs is useful for general tools, but if you think you can just make a whole game using it, ya kidding yourself
i learned HTML before CSS was a thing.. I remember styling tables and stuff by inline stuff
style sheets were revolutionary at first.. and i enjoyed them..
but it eventually outpaced me.. and now theres just soo much i dont know
you cannot access private Functions from another script
is it public
idk how to make it publc
Write the word public
where
you write "public"
Same as the other methods where you wrote private, but the word public instead
DOUBLE KILL
when you dont specify access modifier, defaults to Private
the answer is the same
THAT is actually the wrong script
The issue is with the other one
LogicScript
how can i make changes save that i make in the editor in play mode?
public void AddScore
Make the the AddScore method public in the LogicScript class
you copy the component.. stop the editor and then paste in the values u copied during runtime
million dollar question
if your changing Scriptable Objects i believe they stay changed.. but im foggy on that
Cinemachine can fucking do it, why dont we have an option already
^ oh that one too
aw i thought there'd at least be an attribute or something lol, cinemachine has that
yeah lmao
thanks
Did you see how Cinemachine implemented it? 😄
Paste Component as Values
That's a HUGE mess
this is the best game in unity 100%
Let me fetch it
I smell asset money
just a nice checkmark on each component to "Keep changes after play"
🤫
10/10 graphics too realistic
i feel like it could definitely be a double-edged sword
Holy mother
Who's idea was it lol
what are interesting states lmao
what is reflection
gotta be outta necessity lmao
lmao @queen adder wtf is ur deal? why u being all toxic on my message?
i wasn't even talking to you.. me and navarone were talking
what?
what do you mean
are you high? wtf do u mean what do i mean?
yes
makes sense..
actually no-
where is this?
i google'd InterestingStates and i can't find anything
its like away to inspect all your assembly contents and do stuff with it during runtime etc
binding stuff together etc.
the cinemachine saveduringplay thing
i thought i may find something
thanky 👍
Reflection is also used to get metadata about an object
iirc when you do Gameobject.Find that uses reflection
thanks, unrelated but this KCC is so GOOD man its got literally everything i need for my characters after changing some things 😄
Stop
that tracks with the performance aspect
quit spamming the channel and find somethign productive to do
@queen adder This isn't the server for this sort of crap
Lmao
i know?
What kind of ridiculous response is that
I believe so.
Reflection is pretty much avoided when possible for that major reason, its very slow
that doesn't sound right -- Unity is just looking through all of the game objects for one with the right name
Reflection is necessary when you don't know what you're looking for ahead of time
and have to dance around the type system
ya, im thinking rn how would that fit into Find()
I do remember it was a certain function that used reflection, I dont remember which one tbh
Yeah I didn't think Gameobject.Find used reflection but I didn't wanna say anything to avoid looking stupid lmao
SendMessage, for sure
as well as Invoke
ah yeah that makes more sense
Invoke() uses reflection to
these are calling a method by name, and so by definition have to do reflection at some point
(you can cache the results, at least)
Yeah
There was a conversation on reflection here yesterday too
#archived-code-advanced message
I mean Start and Update is called with reflection in the first place
Really?
Aren't they just derived methods?
iirc Awake uses Messages or Event
there are people that say they're using reflection for finding properties of classes.. soo they can access them via URLs
but idk
Every event messages. How else Unity will call the private methods.
Unless they have dedicated interface like some event handlers
anything prefixed with On is event in MB right ?
Omfg
Unity also lists Awake as Messages
I'm so dumb
@wintry quarry ok, ty. Posted on #archived-code-advanced
Anything that is called without you calling 😏
Awake OnEnable whatever
had no idea those were "Messages" instead of Event
Yeah me either ^^
makes sense though it needs to be broadcasted to all the gameobjects
well, "event" isn't really a thing you'd implement in your class at all
That's why I love this channel my head is constantly blown
that'd be a delegate that you add your own methods to
Unity had this.. design decision long times ago when SendMessage is a preferred way
hey, we all had our blunder years
would you like to see my deviantart OCs
💥
Wdym that's fire!
But they still haven't fixed it 😢
so-called Messaging system
also did you know empty Update methods still allocate
well, still get run
i did not
because they still call to the C++ code
i only know because of the Unity PDFs (trying to find it)
hi guys!
i have a good chunk of Unity's docs printed out in a notebook in my car...
for those times when im stuck out somewhere and need some reading material..
i haven't reached that part yet 😄
Any of the empty methods will still get run Awake, Start, Fixed Update etc. I personally try to avoid having empty methods or just comment them out
yea I don't leave any empty methods
also my "newscript" template is without those Start/Update. I delete them anyway
^^^put them on😆
My new script template is
" Using UnityEngine.
Public Sealed Class ClassName {
}
"
New script template option is underrated
using UnityEngine;
#ROOTNAMESPACEBEGIN#
public class #SCRIPTNAME# : MonoBehaviour
{
#NOTRIM#
}
#ROOTNAMESPACEEND#
Yeah that's mine^^ except I seal my classes
why??
Classes should be sealed by default
If you don't plan on deriving them it should be sealed
theres actually a Empty C# template
and you guys don't use regions??
not sure how u create an empty c# script tho..
Yeah we use regions?
i never do, is there any plus?
A very very very small performance boost
But apparently on some phones there is a considerable performance boost when sealing classes / methods
never tried that, wouldn't keeping the template blank do the trick?
I don't think there is any performance boost
There is
It's just preventing yourself and other people from inheriting that class
Omg I haven't coded in like 2 months
Whats the language C# turns into after compiling
It's intermediate something
IL
what do you guys do?
Check out my courses: https://dometrain.com
Become a Patreon and get source code access: https://www.patreon.com/nickchapsas
Hello everybody I'm Nick and in this video I will explain why you should be sealing all your C# classes by default. We will take a look at the functional aspect of the sealing feature and then take a look at the performan...
I guess one thing is that if you seal your method, and call that directly, that might be some boost because the call does not have to be virtual anymore
No, infact it can be a major pain. Lots of dev's do not like it. Skimming through code and then not being able to find something cause 100 lines are collapsed is so annoying
Oops
I thought we were talking about region not sealed
fyi, using internal and sealed can improve compilation times on a large code base
And yeah seems like same case as what I mentioned, however you don't get anything from just putting sealed keyword on class without virtual method
Ooooh yeah that makes sense
Hold on im looking for the one unity posted about sealing classes
is there a way to make a number go to the power of 2
1 << x
and im assuming 1 is the number that gets put to the power of x?
No 1 is 1 and x is power
1 << 8 is same as 2^8
so if i have a variable that is a float and its called damage and i want to put it to the power of 2.5 what would it look like
Then you use Mathf.Pow lol
k thanks
ya, i don't actually know how to create a script using that template tho.. I just modify my NewMonobehaviour template..
are there any cons to sealing a class?
I think creating "empty C# class" was a thing at some point lol
No you just can't derive anything
ya, cant find it anymore
dont think so
But once you do decide to derive you just delete the keyword lol
yeah lol
one constraint that too can be changed if need be
I've had intense arguments with other programmers on why sealing class is terrible design but all you have to do is delete the keyword lol
don't seem to be issue
yea, i was thinking it may hide/ disable some intellisence stuff..
You spend few more bytes on your code 😄
but if not deriving is the noly con.. i dont consider that a con..
what are counter points?
Sealed my beloved
aayee
My counter point is that I simply dont want to
In Rider I default all my structs to readonly and all my classes sealed 
verbosity
There points where it should be open by default because they are more than likely going to derive the class in the future and it limits what you can do with the class
Limits sound good to me
not that good of a point tbh
But bruh if you want to derive in the future just delete the keyword. You also shouldn't being planning to make everything deriveable
innovations are born from limitations 😉
bawsi got better point lol
Literally lmao^^
Your public API should clearly express what is and is not permissible.
I mean it should be "default" and there should be keyword for "breaking seal"
Had they just said they don't want to I would've respected that more
lol.. i couldn't if i wanted to
If you give someone a sealed class, you are telling them that this class cannot be derived, and that you should not expect to be able to derive from it
If users have to send you an email saying "Hey can you unseal XYZ class for me", that's a bonkers API
makes sense
Any time I try to inherit when it is sealed, I instantly reconsider why I wanted inheritence in the first place, then unless I actually need it, I do it a different way 
That's a good point
good point fen
It's like if you made everything in your library internal by default and only exposed them when someone asked you to
sure, that minimizes your public API surface
but you've missed the forest for the trees
pulls out most unity apis :)
Damn bruh stop making second guess myself

😉
ya, if u look at it like that.. there really isn't a con to sealing it
its sealed b/c its meant to be
not me embedding Cinemachine so I can reach into something internal
Good library should work without needs of user inheriting or access internal stuffs
vee get to unsealing everything bro
okay so I'm trying to load two scenes additively and set the first scene that is not being loaded additively as the active scene. It says that the scene I want to be active is active but I end up controlling the scene being added additively.
I'm not sure what you mean "controlling"
A scene being "active" doesn't mean too much, really
i have a character controller in the second scene and im controlling that instead of the first scene
its ref
You need to deal with input switching on your own
okay
you got controller in both?
it's a main menu in one and a character controller in another
You could honestly leave it for now, and just not continue the practice in the future. Unless you're working in some team itll just be a waste of time
It matters much less if other people aren't using your code.
All additively loaded scenes are going to respond to input
I've started thinking about this while working on an an asset pipeline (okay, a Blender add-on and a Unity importer)
If "what is exposed" is a concern in your solo indie dev project, you probably have to reconsider your concerns. People go way too hard in the design aspect sometimes
even if i set one to active?
Yes.
Correct
got it, thanks
Most code doesn't care about the active scene at all
there should be better input handling
Are you using the new input system with PlayerInput components, by chance?
yuup
Each PlayerInput corresponds to a different player
I bet Unity will eventually add new-new-input-system and new-ui-toolkit 😦
If you have two of them enabled at once, the input system thinks you have two players
nooooo
I think you can just disable the PlayerInput you don't want to use.
emphasis on think..
That'll come after Unity 7: 2026.2.3f1
Personally....I like the new input system lol
I love the new input system
the New Input system will become the Input System and old Input class will be Legacy
okay ill try it out hahah
my game supports mouse and keyboard as well as gamepad (with steam deck gyro input!) input
I think people like the old one because it's simpler
im just now going on my blinddate with it
I can pull up sprites for any input control, showing the correct sprite for the current platform (well, that's my code)
But you can do so much more with the new oje
i dont use unity's input system
and show appropriate hints based on your control scheme
Do you use a package?
Have you tried it? It is very worth it
It really isn't that hard
maybe I should make this into a package
Old one is nice for quick testing, but is such a hassle if you need any kind of multi-device support 
Exactly
^ thats the transition point for me
never felt need to. will check it out
if im only writing for mouse and keyboard i'll use the Input class all day
#💻┃code-beginner message
It seems like you see the need for it at least
as soon as i think about 2nd control devices its a must
I ask my system "what's the sprite for <Keyboard>/a?" and it fires the appropriate sprite at me
wdym
Yeah and the new input system makes it ez via raising events for which controller is being switched to. So if they switch to keyboard then all of the UI sprites for keyboard will show and vice versa
Yep.
is it possible to use 2 input devices for the same map?
You said there should be better input handling. And there is! It's the new input system
An input action map is just a collection of input actions.
But yes, you can have multiple devices providing input at once (hey, that's mouse + keyboard)
yea,, like using a joystick in one hand. and numpad for the other
I also like the idea of my game having actions that are called rather than inputs
Oh yeah I did something like that too for my game. Swapped fonts/sprites/etc based on the input device (and refreshed in place).
oh i meant input handling in that person's project
I set up my gamepad control scheme to also allow for a mouse. That lets me use the gyro input on a Steam Deck.
Huh never thought of that
Ahhh, gotcha. Misunderstood
np
lol.. 🤦♂️ me when i realize mouse and keyboard are two different peripherals
It'd be nice if I could do that more directly
but I guess this isn't Steam Input.
im using a kinematic character controller, how can i make it so when it hits a wall or a ceiling it sets vertical or horizontal velocity to 0?
I assume that stops the auto-switch to the keyboard+mouse map if you never touch the keyboard
i dont use it, how would i know if its good or bad lol
It is good
And at that point it sounded like you just didn't know about it
Correct.
Kind of incredible how accessible all of these features are and they are free. I could only imagine having to write all that shit myself
collision event.. -> set velocities to achieve desired result
Which I'm not a huge fan of, but...ah well
Correctly handling both gamepad and mouse interaction in your UI is fun
On my Deck, the pointer winds up causing random buttons to get highlighted
(even though it's invisible)
maybe I should just lock the cursor when you enter the gamepad control scheme
Focus things with a virtual cursor instead 
i have a flight sim where i like to use my joystick. but i also use my numpad for hotkeys..
problem with it is.. when i use the hotkeys.. it disconnects the joystick.. and i have to flick around the joystick a few times to get the gamepad working again..
aeugh
if i use the new input system.. i just want it to not do that
I actually need to make that for my point-n-click-esque game to even support gamepad
But I am lazy
I just make sure to have good explicit navigation
but like how would i determine whether i've hit something horizontally or vertically?
i will use it when i pick up something new, currently stuck on grids 😑😑
You mean like A*?
combination of colliders and logging the velocity u currently have when u do collide
just build a generic dynamic input system based in the new input system but without using any of the Unity high level crap. works perfectly
ahh good to know its possible and simple 🙂 i'll do some further testing.. Thanky 🙂
sounds like you just need to include the numpad into the same control scheme
ya, that was kinda my original question..
Yeah.. Editor integration is confusing
Correct.
wasn't sure if that was a common practice w/ the new system
Steve has the point 😄
how much experience do you guys have??
2.57 yrs
~7 years
damn
this is my prototype GamePad function selector
Unity specifically like 7 year? Not even sure anymore. Coding almost 10
very specific
steve is on up there too
You can also just not have control schemes
in that case everything is used all at once
almost 50 years
where the average person has about 30 trillion inputs
Lot of fingers
wth, you were making games on paper or what
LMAO
lol.. he was programming on Commodore64s
getting his code from a black and white magazine
before your parents were born, guess what we had computers
😄
before that
Man was turning light switches on and off by hand
thats as far as my context goes
funnily enough, they were called plug boards and, yes, I've worked on them
Wait really steve? This is personal question but how old are you bro?
nearly 70
he wrote the instructions on paper for that probably and gave other guy to do it😂
my dad showed me some of the old magazines he'd buy and it would have programs/games code in a little article.. that u would just copy over to ur commodore.. and boom.. free game
well - the cost of the magazine
Bro i wouldve nevered guess you have a young personality
damn ARE YOU FOR REAL??
To be fair. I write pseudocode on paper before starting to code usually
As well as graphing the architecture
i'll do that with flow-charts and mindmaps
Thats honestly cool af i hope to be coding by that age
but not code
and guess what, I still spend 18 hours/day 365 datys/year designing and developing systems
you got 7, not that far ahead
ya, the architecture
What?
there wont be coding in 50 yrs, prob not how it is now
abso-fucking-lutely
ya, mad respect for the OGs
being ancient
Epi means AI i think
really
I have no idea what you are saying
No need to insult people though, which is what that feels like
Yeah Epi i love you bro but i dont know what ur saying
that new langauge barrier thats forming 😄
my brain is convinced that I'm still 24, by body tells it to fuck off and grow up very often (brain tends to ignore body)
okay yeah nevermind i didnt have to load scenes additively, i literally only had to make my character controller accessible to both scenes and it works just fine. dumbest person alive right here
Sorry homie lol
good way to stay young 😄
ah, there you go (:
not dumb if u found a solution
happens
it was a sensitivity slider so i just had to make my character controller an asset to access the script ig, i make things too hard for myself
its cool
its hard to code things exactly how you'll need them in the future.. hindsight is 50/50
next time tho, it'll be more str8 forward
@languid spire do you find anything new to learn at this point??
I think so lol. Comp Sci is such a vast field
its a trade-off.. between the time u spend thinking about how a system is going to work..
and just doing it
Industry has so many new things
Yeah and theres always new stuff popping up
ya thats what i was thinkn.. its a good field to be in if ur watching for innovation..
yeah bro but think about the exp he got in having everything 50+
Thats why you gotta respect the OGs
Well, yes, as long as people like MS and Unity keep finding interesting ways of fucking up computers, I keep finding ways to get round them. The IT industry never stands still so neither do I
true
LOL😂😂
seems like this is how its ALWAYS been
and always will be
Now with AI ™️
Whats everyones current project that there working on? Im trying make a Immersive Sim rn
yep, before it was MS it was IBM, but the same applies
i working on a makeover game 🥲
Makeover?
working on a Template project.. w/ universal snippet code that can be just dropped in to 3D, 2D, or 2.5D sets.. with materials, textures, and all ur basic stuff
player controller, mouse controllers, audio managers, ec
merge grid game + makeover stuff
Oh thats pretty neat!!
everything except grids
Let me know how that goes
i hate working with grids lol
Oooh thats pretty cool too
its in production lol
Gotta start somewhere
In production means it's close to launch
am i using movetowards wrong?
if (Mathf.Abs(currentVelocity.x) > maxAirSpeed && !launched)
{
currentVelocity.x = Mathf.MoveTowards(currentVelocity.x, Mathf.Sign(currentVelocity.x) * maxAirSpeed, maxAirSpeed * dampSpeed * Time.deltaTime);
print("Damping to " + Mathf.Sign(currentVelocity.x) * maxAirSpeed);
}
Oh shit lmao my fault
it doesnt seem to be actually moving towards
Wait really? Send me the link!!
I dont think u can send it here
ur print doesn't log what u expect?
its shit bro
Still i wanna support you
just did it for my employer
no, it does say what i want it to, but i cant see the velocity actually changing to reflect what i want it to do.
this game earns like hell bro, considering all the things
Could you share the full class
are u setting ur velocity directly somewhere else in the code?
There might be other code overriding the velocity / position
will pm you link later vee
^ my guess as well
Bet homie
Glad i could be of help lmao
you made me look at the whole method so you did help in some way
made me spot the problem
Rubber duckie
Thats good at least. Always glad to help
https://en.wikipedia.org/wiki/Rubber_duck_debugging It has dedicated page? lol
its very famous lol so obv
wonder what it was called before 1947 😈
nope, i thing it IS steve's
Leave the OG alone lol
ffs, I'm not that old
steve, sir, by any chance you got nickname bob??
no, I dont do nicknames
i keep my rubber duck w/ me at all times.. even in the project 😄
keep an eye on it bro, looks like its planning to destroy you
ya, hes mischevious for sure
cheers to those who helped me earlier, got my code fixed
I have heard rubber duck programmers are genius people I don't know what does that mean 😉.
how do I set the individual x and y of a vector 2 while using the visual scripting system
It just means you talk about it and figure out the solution. It comes from describing the problem to an inanimate object, like a rubber duck, to organize your thoughts and solve it
There should be a vector2 node, which has x and y inputs
But I dunno. I recommend just moving to real code
Split vector then change values and make another vector
Oh so talking and figuring the solution is rubber duck. Now I understood that.
happens alot.. sometimes u can see someone typing.. and typing. and typing.. and then they just stop typing. and u never see 'em send the message
rubber duck action.. most likely 😄
Oh I see that's a rubber duck got it.
hmm, when other humans are involved its called confessional programming... interesting
I just talk to myself, all day, every day. Most people would call that insanity
nah, ive heard as long as u dont answer urself ur okay 👍
i often point my arms around when figuring out anything involving vectors
Why so Steve.
get u some scratch paper man
who the hell else would have a hope of understanding me?
That's right other than you nobody.
been lots of teetering offtopic today.. i guess no ones coding today 😦
imma get to it i guess lol ... Editor scripts calling my name (possibly UIToolkit)
Giving a lecture tomorrow which I dont really want to do, preparing for it
Been doing it trying to make a scene portal. It's not easy trying to throw some objects from one scene to other.
like a scene selection screen/menu
Just store the velocity vector 🤷♂️
No like a teleportation portal.
ohh.. ya those can be tricky at times.. esp if u have first person controller / mouse controls
sometimes u gotta cache or offset ur mouse position.. so ur not looking in some odd direction
esp if u do any rotations
i imagine ur doing additive scene loading?
thats the way i'd do it..
just load in ur new scene, and unload the old.. keep ur player around
Yes storing the velocity is working but for few it's like you see scene 2 from scene 1 and you can jump into scene 2 and making damages to scene 2 objects you see from scene 1 but I have decided to make probably upload a video after finish.
How can I return a number that is within a range based on another range?
I think that I might need to normalize it first, but I dont know:
Example => I have power of 1 to 10(float) and I want to return a value between 5 and 50.(Power 1 = 5, Power 10 = 50)
How would I do that?
This has to allow numbers above/below those i.e. power -10 would just return 5(lowest value)
Remap function
Some of these solutions already clamp it
some don't
For example this will clamp: https://forum.unity.com/threads/re-map-a-number-from-one-range-to-another.119437/#post-3451703
oh this one looks nice too!
I think I finally understand the feeling of not realising how stupid an idea is until you're too far in to quit
sunk cost fallacy. you can give up on a bad idea at any time
Visual scripting is harder than actual code
I wonder who uses visual scripting(like in real world in real projects)
Does it even make sense? I know there are blueprints in UE5 and I've seen people do well with those(similar to Unity shaders?)
If anyone does I pray for their soul
Its interesting, cuz gms2 used(or still does) market itself as being easy to access with visual scripting, but I wonder how many people actually use it.
Unreals blueprints are definitely more viable to a certain degree. But yea for anything large itll always be worse than code. Which is why shadergraph is so nice to use, I dont have to learn shit
to be fair it isn't too difficult to do better. like 2 lines of code absolutely should not need more than 5 nodes#
Can you create custom "functions" using nodes?
This way you can have 1 node that has multiple nodes inside?
I dont think so
I only saw something in Unity shaders, but I'd guess it would be logical to group nodes together into a "function" so you can reuse it.
that would be so nice if it was a thing
theres like a whole tab dedicated to one very specific node though
just incase you find that useful
I didnt play with that yet so idk 😄
ill leave the fun to you
So I was messing around with abilities/relics for my 2D top down game. The problem I am running into has a very easy solution, but I'm just confused on something. So pretty much the problem is that FindGameObjectWithTag can't be called in a constructor, which is fine, but the confusing part is that I actually already did this for another script a while back, which did not generate any error. I'm just going to move the code to Awake rather than a constructor, but I was just curious as to why one constructor generates this error, while the other does not.
Error Code:
public Stoneskin() : base("Stoneskin", "Increases armor for a short duration.", "Basic", 125, 10f)
{
playerObject = GameObject.FindGameObjectWithTag("Player");
armorIncrease = 5;
abilityDuration = 3f;
isActive = false;
}
No Error Code:
public PreservedLifebloom() : base("Perserved Lifebloom", "Increases max health.", 15, RelicCategoryType.StatIncrease, RelicEffectTriggerType.Passive)
{
GameObject playerObject = GameObject.FindGameObjectWithTag("Player");
if (playerObject != null)
{
characterStats = playerObject.GetComponent<CharacterStats>();
}
maxHealthIncrease = 50;
}
You should not be using constructor for MonoBehaviors
It's fine for regular classes (non-MB)
Are these classes MonoBehaviours? You should not be using a contructor for them at all if so
is there a library i can download to draw graphs?
A constructor may execute at unusual times
oh sorry neither are mono behaviors
But I think you are initializing one of these objects inside a MonoBejaviour field initializer
I know that constructors can get called as part of serialization
For example you have like public PreservedLifeBloom bloom = new(); in a MonoBehaviour
ohhh ya i do
In which case you need to move that constructor invocation to Awake
QUESTION!! I have a 2D object at the top of my project's screen, and I want it to be frozen in place on the Y axis (while able to move on the X axis with player input, this I've already figured out) until the player hits a button the keyboard (space bar or e or something), which then allows gravity to effect it and let the object fall. I've been googling like crazy and going over the Unity Documentation, but I haven't been able to find anything to help me accomplish this.
TLDR: how to script to get a 2D Object to stay in place on the Y axis at start (not be effect by down or up gravity) BUT when the player hits an assigned key, the gravity effect resumes and the object is able to move on the Y axis (falls)?
public Ability testAbility = new Stoneskin();
This is in my abilityManager code xD this would be the issue right?
give it a rigidbody, either make it kinematic or set gravity scale to 0 until that condition happens then make it dynamic with gravity scale 1
Yes. Move the new Stoneskin() part to Awake
tyty!
It has a rigidbody, how do I make the gravity scale change from 0 to 1 when a condition happens?
Sorry, I'm extremely new to C# and coding in general, do I just put public float gravityScale; into a new script attached to the 2D object?
do you know what an if statement is?
you would need to reference the rigidbody first to access its methods/properties, you need script attached somewhere on that object
I would probably start with !learn though
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
I've done the Unity Essentials Pathway in Unity Learn, but I definitely still have more to learn! Was just trying to see if I could figure out this idea, but I'll try to dive deeper into the stuff available on Learn.
Thank you for your help!
after essentials I say to do Programmer pathway at minimum
will do! Thank you :)
goodluck!
I'm sorry, I don't! (or at least I don't remember if I did learn it before lol)
then 100% start with some beginner c# courses
makes sense to me, thank you guys again!
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
just started a c# course on udemy, how do you guys rate it as a learning platform for learning c# and unity ?
if you are paying for it, a waste of money
why is it a waste ?
MS and Unity offer better tutorials and learning for free
for some reason i couldnt get the unity learn site to load on my pc so i gave up and went for a udemy course for c# and unity
did you try the MS site to learn c# ?
no
this ?
yes
me? 50 years
then you definitely need to try to get !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
99% of paid courses are shit. I knew a guy who in his first year of uni published a python course while also not knowing what a loop is.
Courses, teachers, and "coding gurus" have become plagued with being the first and loudest.
It can be slow loading at times. Wait for it to load or try a bit later.
yeah i have had some slow loading times that have made me give up with it
probably on my end
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 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.
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Assertions.Must;
public class Grab : MonoBehaviour
{
public Transform heldObject;
public Transform mainCam;
public bool holding;
// drag system goal when holding click the item is where the mouse is + get it to build momentum
private void Update()
{
Vector3 mousePos;
mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
mousePos.z = 0;
RaycastHit2D rayhit = Physics2D.Raycast(mousePos, mousePos);
if (rayhit.collider != null && Input.GetMouseButton(0))
{
holding = true;
heldObject = rayhit.transform;
}
else
{
holding = false;
}
if (holding && Input.GetMouseButton(0))
{
Rigidbody2D rb2d = heldObject.transform.GetComponent<Rigidbody2D>();
if (rb2d != null) heldObject.transform.position = mousePos;
if (rb2d != null) rb2d.AddForce((mousePos - heldObject.position) * 6f);
if (rb2d != null) rb2d.velocity = ((mousePos - heldObject.position) * rb2d.mass);
}
}
}
i want to make it so when im dragging a object it can build momentum and would get flung when let go any ideas?
you know you can put more than one statement inside an if statement, right? you don't need to check the same condition three times in a row
you would be correct considering i just copy/pasted the exact message
I also even showed you the TryGetComponent way
i dont know what trygetcomponent is or how to use it
i can only presume what it does at the moment
you might also consider posting the code correctly considering you pulled up the bot message
steve how should i post it?
'large code blocks'
so i just paste it an send a link?
oh nvm I only suggested it but not typed it, looks like stevesmith was right
My Player should stick to the "train" when getting on it but its just standing still, I made the player a child of the train as soon as he gets into the hitbox and that works fine its just doesnt stick to it heres a video: (in the video the playerobject dissappears because it gets the cild of the train)
...did I travel backwards in time
btw you mentioned a crashcourse any ones you would reccomend
the microsoft ones for C# specifically, Unity learn for mix of both
also where should i do this?
wdym where? there are three consecutive lines where you use an if statement that checks the same condition
oh yeah thanks
I also have a character controller on my player if that helps
whats the problem
not an issue
i just want it so
the object im dragging
can build momentum and when released it gets flung
And my problem is that my player doesnt adjust its position although its a child object
why would a player be a child?
what have you done? just stuck it as a child and thats it?
yep
do you have a rigidbody?
yes
then you need to update the position on that i think?
and character controller
and on that also then...
but a child object should copy the movement from its parent automatically shouldnt it?
yes but you need to update the components because of the physics and stuff, im not sure exactly how it works but im pretty sure thats what you gotta do
ok yeah but how do i find out how to do it because i have no idea either thats why iam here 🙂
just .position on the rigidbody
i think same with CC but maybe not
yeah but which value?
but thats not moving thats the problem or do you mean the transform.position from the moving platform?
oh right, try doing it the same as the platform? the X is all you need to change right? so that should be pretty simple
hm that sound like a solution that will get me in trouble later
but sounds good
haha
i mean you have to update the rigidbody somehow
perhaps just not make it a child and move it manually, im not sure exactly how moving platforms are supposed to be made
you could watch a video on it if you havent yet
oh yeah i found one
very nice advice thanks(not ironic)
Ok the solution was: The moving platform has to move in the "FixedUpdate()" Method and not in the "Update()" Method it probably has to do with the charactercontroller updating as you correctly said
I just realised if an object falls with enough speed, it ignores colliders? Not sure if that's intended by Unity or not?
yeah i mean same thing happens in most games?
Whenever I try to rotate my gameObject, it spawns a clone of it. Here's the code: https://pastecode.io/s/09qwryx7 https://pastecode.io/s/z4i3hhyd
Does it? I would have expected it to maintain the collisions no matter the speed of an object
i mean depends how fast, you can do things to make it better
Make what better
the collision detection
like changing the collision mode on the Rigidbody
Basically I increase the gravity scale
So at some point of falling it's too much to register collisions
Don't crosspost. #archived-code-general
yeah i think no matter what at a certain speed it will always avoid collision, but you can do things to make that speed of failing collision higher than normal
Neither of these scripts have any calls to Instantiate or new GameObject() so neither one can be spawning new objects
It does in another script
then SHOW that?
how can we fix a problem where we cant see the problem
oh right it was a crosspost i forgot
though these scripts are beyond saving or refactor. It should be redone as suggested
Exterminatus is the only solution
What's exterminatus?
warhammer
Complete annihilation
you do it when you think one person on the planet might have said something chaotic
planet explode
A completely reasonable reaction to heresy
Any Tilemap enjoyers that could help for a quick question?
Documentation is so scarce geez
https://docs.unity3d.com/ScriptReference/Tilemaps.Tilemap-origin.html
I have a question about the Tilemap Origin. It should pick the lowest point of the tilemap, but if I draw tiles and erase them, it keeps the lowest point that has existed. Is that behaviour expected?
tips for having prefabs reference objects in scene?
i hear using Find is less than ideal usually
hey guys, how do I get more fonts for text mesh pro? I'm tired of the default one
- Download font
- Add font to your asset folder
- Create font asset: https://docs.unity3d.com/Packages/com.unity.textmeshpro@4.0/manual/FontAssetsCreator.html
Yes, you would use a normal font file
You can generally just leave everything default
i see
my font file type was called TrueType
when i did mine i never had to make an atlas it let me use it as is
are you able to drag the font into your TextMeshPro?
or select
ah nvm I figured it out
thanks for the help
What's usually the fix to prevent vibrating against walls by walking into them with rigidbodies using MovePosition
what is the 2d equivilant to Physics.OverlapSphere
would it just be Physics2D.overlapcircle?
thankls
How would i access this material on my zombie and change the alpha all the way down?
My rigidbody's do not stutter if V-Sync isn't on. I don't get it, it seems that Time.deltaTime is very unstable and jumps to extreme values with V-Sync on. My character stutters when turning even with interpolation on, AND using CineMachine.
Is this a code question?
If ya doing rigidbody methods in update, those should be in fixed
Physics should not be effected by VSync or framrate. Are you sure you are doing your calculations in FixedUpdate?
Yes this is a huge problem tons of people have and I can't seem to fix it
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.
This is the code for my player controller, I've had numerous conversations with people and we still haven't figured it out.
first line of code you're using forces in update
what unity class is this?
No I am not?
Yes, WHen the zombie dies
I want to change the alpha down
Gradient?
To simulate it fading out
I see addforce calls in update. The jump one is ok, since it is impulse, the other is not
Not sure how to access that if i have multiple zombies tho, nmor why its bvlurred out
There aren't any other ones.
Oh
That one isn't even used as I never jump in the game.
Also it's adding force downwards.
Yes, that is the one that is an issue. Not necessarily THE issue, but an issue
dunno, imma just use it to make an image generator with perlin noise, is that doable?
Can also try tossing the camera into other update methods besides late
cinemachine has its own toggles for that too
dont have that class ig
Gradient??
This is a video with camera updates in late update and no forces in update.
seems like a typical rigidbody/camera desync problem + interpolation
How do I fix it then?
idk those I just mess round with the camera update methods
there should be a suggs if there is
I've had this problem numerous times.
It's been 2 weeks of trying.
Looks like your IDE might not be set up fully, but who even knows. I don't use VS Code
if you just do public Gradient gradient and save it, does it error in unity?
yea, seems like i just dont have it
That's unlikely to be the case.
hmm, then why i cant even new it 🥺
Presumably because you're doing it wrong

