#š»ācode-beginner
1 messages Ā· Page 218 of 1
the direct answer to your question, is it depends⦠on the units of what you have
mmm pointers
serialize a pointer lol
I know, wrong syntax, but that's the concept I'm trying to accomplish
void *?
No bro lmao
public UnityEvent onCustomState1;
Just do the type and youll get ur reference
that way, the bool* can point to a memory address on my computer, I build, someone opens it on their switch, and then it accesses the memory of the same address and seg faults 
Ok, so when I'm applying forces to an object in general I do not need to multiply the forces bt Time.deltatime (?)
look at the units
If you want to expose an event that you can set in the Inspector, then use UnityEvent. If you need it to take a parameter, then use the generic version, UnityEvent<T>: UnityEvent<bool>, UnityEvent<GameObject>, etc.
Also look at the docs for the method you use
you could use unity events.. or u can reference the scripts u need to call methods from on the Controller script
otherScript.DoSomething();
ur switch statement could call w/e
at this point im confused on how ur project is set up.. lol
but what if he wants to disable the button at anytime.. that script would have to be on the button itself
ah thats true
I believe hes left
Sorry, no still here
to get ready to publish i bet ;D
using UnityEngine;
using UnityEngine.UI;
public class ButtonController : Selectable
{
private enum ButtonState
{
Unpressed,
Pressed,
Latched,
}
private ButtonState currentState = ButtonState.Unpressed;
protected override void Start()
{
base.Start();
onClick.AddListener(OnButtonClick);
}
private void OnButtonClick()
{
PressButton();
}
public void PressButton()
{
currentState = ButtonState.Pressed;
PerformAction();
}
....etc
As soon as I get the multiplayer and inventory system then yeah you betcha
when adding force, the force you add has units of force (Newtons are mass * length / time ^2)
if the formula you write when adding force does not have those units, what will happen is that you will tune the numbers until they look like they work right, and then later in development when numbers change, everything will break again. Because the formula (with wrong units) is wrong
this applies to any physics code you write. It MUST obey units, or the result is guaranteed to be incorrect
if you write:
rb.velocity = transform.position - secondTransform.position;
i just wrote meters to speed, but speed is m/s. This will be wrong
Yeah the fromulas that I wrote are right (or at least they are what I remind from my school studies hahah)
Alright yeah, UnityEvents are definitely what I was after, but I will do some looking at the Selectable class.
š
and just looking at youtubers who say āyou need to multiply by delta time for it to be consistentā is bullshit, because that is not how it works
UnityEvents are awesome/ lazy š j/k
If it were up to me I'd do it all in code, but I'm trying to make it convenient for the other guy to work on a UI. Thanks for all your help!
I just can't really understand at 100% how do Update differ from FixedUpdate and in which cases I should use Time.deltaTime or Time.fixedDeltaTime
And thanks @queen adder whoever else
The Selectable class enables u to use UnityEvents
The Selectable class just lets u make a Button but with extra logic
rb.velocity = velocity;```
Well really ANY class can use UnityEvents
Unity runs one FixedUpdate frame every fixedDeltaTime. You might get several Update frames in between. The physics system only performs simulations on fixed frames
so you can be running at 500 FPS vs 60 FPS, and still maintain 30 fixed frames per second
if u set a RB velocity in update tho it'll wait until the next fixed update before it actually impacts the RB
at 500 FPS, you call Update 500 times, and FixedUpdate 60 times.
At 100 FPS, you call Update 100 times, and FixedUpdate 60 times
per second
Is it ok to perfrorm some math like this in FixedUpdate?
50 times* per second. Fixed Timescale is 0.02 by default.
right. depend on settings
nuh uh
point being, fixedupdate is on a fixed schedule
Update is not. And you can sometimes get a lot of Update calls between physics simulation steps, and sometimes not so many Update calls
well if ur rigidbody is respecting phyiscs.. then sure.. u run u calculations and then send it over to the rigidbody.. all will happen within the same frame
Thank you all for your helpāļø
it is calculations for the physics after all
as a general rule, you should only touch rigidbody fields/parameters with setters in Update (or non fixed update frames) IF you are initializing (or related non-physics movement)
Does anyone also know something about this?
I finally got the door working but my script to play a random sound of 4 when moved isnt working?
might be somehting to do with this
well yeah but i dont know what that is
scripts dont run like they should when they're popping Null errors all thetime
so you should not be modifying rb.velocity or rb.position, or calling rb.AddForce or rb.MovePosition in Update
that doesnāt make the problem go away
it means somethings not assigned correctly.. its trying to access a script u havent told where it is
if you get a null reference exception, usually everything in the game is about to break
script go bRrrrrrrrrrr
because youāre usually breaking out of a lot
Something on that line is null but you're trying to use it anyway
like cutting off the program halfway through a frame
double click on the error, and it will take you to the problematic line of code
it also tells you that the error is on line 43 of that file
Okay, so another basic question regarding how events work...
Button button = GetComponent<Button>();
void doThingWhenPointerDown(){ }
//make button.OnPointerDown cause doThingWhenPointerDown()
What's the syntax there?
its line 69 now
doorSound.PlayOneShot(doorClips[Random.Range(0, 4)]);
then you best figure out why doorSound or doorClips of that index are null
Button button;
void Start()
{
button = GetComponent<Button>();
button.OnPointerDown.AddListener(doThingWhenPointerDown);
}```
you need to call button.OnClick.AddListener(
Wdym?
Are also raycasts called every physics frame?
Sweet, thank ye
if they are in the update yea
Why not just put the method via the inspector
They are called every time you call them
Might be every frame if it's in update
the only physics unity will do for you is Physics.Simulate. If you are raycasting in Update, it is because you put it there
unless they're wrapped in an input or something void Update()
if (Input.GetMouseButtonDown(0))
{
Raycast();
}
That method in particular is just related to visual stuff only effecting the button. So I don't necessarily want it in the inspector.
the computer will not ask questions if you raycast in update, but we will judge you
I'm creating a car and I'm actually setting the wheels positions using raycasts
cool. i do that for suspension
Is it acceptable if I put it behind an input?
I noticed that using raycasts in Update() works fine for setting that positions
Ppl use Raycast In Update All the Time?
But it's "slow" if i use raycasts in FixedUpdate
for Inputs yea
wdym input
like when u click mouse -> raycast into the scene -> get position
Ppl use Raycast for other stuff to
not only. I use it for checking slopes, climb mechanic etc
in general, if you are using old input system, you want to store logs of input in Update, and then action on physics queries linked to them in fixed update
I cannot remember the effing name
how do you change the render order of ui elements?
Stealth Games
Like(Input.ButtonDown(āEā)
sorting order
hierarchy
Something like this, I donāt have unity in hands rn
i mean how to do it from script
switch the child order
If the rest of the object is moving in update, itll definitely look like the wheels are off too
you can switch the child order in code?
ofc
if you use the new inputsystem, you invoke a function, Iāll normally store input variables there, to then do stuff based on input variables in fixed update
setsiblingindex?
yup
sweet
but i would rather do any sort of casting in fixed frames only
the way i learned quickly is.. whatever u do in the editor with ur mouse.. u can probably also do in code
casting in Update is bad juju, because you are querying while things could be changing leading up to a physics sim step
There's absolutely nothing wrong in using Raycast in Update, because the result is instantaneous.
you usually only run physics queries for physics reasons
how would u split it up? or would u just get ur input in fixed? and then cast.. but then u might miss the click?
Especially if you're checking for the floor.. it doesnt matter because the floor doesnt move
I'm actually applying forces only in FixedUpdates
Raycast arent that slow
thought so
I think you've developed a misconception that EVERYTHING physics related must be done in fixed update. This really isnt the case
In old input system, Update checks inputs, stores some bools/floats/etc to log what is going on. Then in fixed update, you actually do physics
It would look like shit if an object moved in update while the wheels move in fixed update
Where it causes issues is when stuff is applied over a few frames, like an AddForce call. If the framerate is inconsistent, the applied force smoothed over a few frames will appear inconsistent. But not for one call, an instant velocity change, or a physics cast
ohh thats tedious
ill keep casting in update š
god bless the person who thought to code the SetAsLastSibling function
In the newest one you need to create a method for that (not necessarily)
And you can use your logic there
wtf is creating a void ?
every time I try casting in update, I get the āold infoā problem, where the timing in frame doesnāt match what is going on with the rbs
I think he means a void Function
man if he created a void we'd all get sucked in
Yes
how fast is your shit moving š
because you can be moving rbs within fixedupdate
Just say create a method
i know.. just a bit of trolling
And yeah, new input can be callback driven
i try to move things very precisely, and I have a custom physics engine, so if Iām slightly off, itās a big deal
i gotta learn the new input system (āÆĀ°ā”°)āÆļøµ ā»āā»
Its not hard
Ur a pretty good coder Spawn so youll prolly learn it pretty ez
if you fuck up slightly with a dynamic rb using box2D, unity will automatically depenetrate you before it does anything
Method. void is the return type.
What do you call this:
int GetNumber() { return 42; }
An "int"?
its 1 component lmao
lol sure thats what it is ;D
ya, but theres like a million settings.. like if i want mouse input theres like 5 different ways to send it
A void int 
Honestly itās really good, for setting up controllers and stuff, but itās more complicated than the old (personally)
this happened to me a lot before I made my custom physics engine, where Unityās box2D usage would fix a lot of my sloppiness
It is way more complicated
yeah options are nice š
And honestly the API is not that great
Trying to set up KeyBinds at runtime is fucking annoying
I know how is it called, I wrote āvoidā just to be quick
new input system is more complex, but it is so much better, because you can tie functions to events for specific inputs
ya its hella expandable
Never again
method is 2 letters more
Iām That lazy
in new Input system You can do polling too if you're used to that
instead of checking āiS tHiS buToN dOwN nOw?ā every goddamn frame, in every script that responds to input, like a buffoon
that pisses me off so much
if(Keyboard.current.qkey.WasPressedThisFrame)
thats the way id end up using it.. Current.Keyboard...
That only checks the keyboard tho
Honestly i like using UnityEvents the new input system
yea, that..
Not if you press from any other input device
you can also use Device.
iirc
I just use the Messages though so its no problem
true.. but im not developing for controllers..
Its really intuitive you just write a function and it gets called
KBMR!
I'm gonna be that guy, but you called them "void" 6 times, "method" or "function" only once...
No Update no references
So yeah nice excuses my man
Just call a function when the key is pressed
my issue is that the new input system would benefit from more documentation/help. going through youtube guides is necessary, and also makes the process way hardee than it needs to be
yes events are great
Did you really checked all my messages š
#š±ļøāinput-system needs a little more activity imo
we need more people who are experienced with it chill there š
Ok then I admit it, I did not know how a void was called
inputsystem is just better than input
am experienced, but am not chill
It comes with its own complexity tho
There weren't many matches lol, plus it displays a count at the top of the results page
I solved it by using the raycast in Update instead of FixedUpdate
aye, nice.. as long as it works.. it works
Lmao
You won, honestly I cannot say anything
It's called a return type
Paradoxical type, void is a return type, that indicates no return value
Describes something that doesn't exist
Bro it was a simple mistake lmao
Yeah?
Why are yall going off on him
I'm not
any idea what this means and what I should do?
He is the programmer grammatical police
it'll definately be burnt into his memory
š
For sure lmao
void isnāt a return type. it is a keyword for ānothingā
Shouldn't this work?
seems ur branches have diverged
arrays cannot .Add
Just wait until I see someone naming something incorrectly regarding the C# naming conventions lmao
what does that mean?
lol
no clue
we had someone earlier with lowercase function names. go getāem!
Then.... what?
Did u set your git to unity?
I am really confused
Using Java naming in C# is a clear violation of the Geneva convention
no, you only need to do it in VS
and it's been working fine until today
You can use Array like that? Hang on what
Array.Add is real ????
No you can't
Hi Learners,
Most of the time while working with local & remote branches in git, you might have come across this error while trying to pushā¦
it sounds like one of the dumbest ways to use an array tbh
Then how do I "add"?
Wait what, wasnāt arrays like static. You cannot change its length on runtime?
this is unity's Array class. and according to the documentation is only available in javascript
https://docs.unity3d.com/2020.1/Documentation/ScriptReference/Array.html
The Array class is only available in Javascript.
use a List<>
you are looking for a List
the whole point of an array is that its length does not change
Yeah that explains it. System.Array is abstract, you cannot do new Array() without it getting angry at your face
Then I have to change these to Lists?
you cannot change the length of an array. that requires you to make a whole new array
you should use lists yes
if u plan to add and remove
if u need a fixed length list then use an Array
Lists are better for games in general IMO the performance cost is worth it
Do List<Material> material = new List<Material>;
i always use lists for some reason
the whole point of a List is that you can .Add and .Remove entries.
Lists have other features, but the main feature is .Add and .Remove (RemoveAt)
Same
Can I add a LIst to the materials? I though it only accepted arrays
Material ***
You'll quickly learn that Arrays are a bit cumbersome to use, and that Lists are the goto collection for most tasks.
This time I didnāt even made an error š
i know right.. š sorry
@rancid tinsel is that helpful?
Pointer to pointer to pointer to Material
Kinda sad they removed js support, but C# is 100% better
row row fight the power
Monoscript?
Also, arrays aren't ordered rigth?
it was that language that they used that was based off JS i thik
UnityScript š¤¦āāļø
i decided to just merge it and it seems to be fine
thanks
np š
Do you know whatās an assembly definition? I saw it in unityās microgames
what does ordered even mean?
ofc they're ordered
you just put things jnto different indices
0,1,2,3,4... etc
that isnāt an order. itās an index
to me is a vague thing.. but its basically a group of scripts and all that is its own DLL after u build..
because the array is just a pointer, and an index takes you straight to a spot in memory
when Unity recompiles.. it recompiles each assembly def
Not true
so if u use multiples u can keep it from compiling ALL ur code
Like this then?
It will actually only changes the ones that have been modified
unity only recompiles assemblies that changed, or assemblies that depend on ones that changed
thatās half of the point of using assemblies
So basically make compiling faster?
the other half of why you want assemblies is to break shit up, and especially to use the internal keyword
You can get namespace conflicts super easily
just dont worry about assemblys just yet
if you donāt use assemblies, internal might as well be public
in the future u may want to go back and learn em/ use em
Thanks for the help
you can wait until a lot later tbh
I completed a few months ago junior developer pathway, just wanted to learn more about unity before starting some real projects
part of an assembly is how dependencies work
hello is there a support channel here?
!support
Take a look at #šāfind-a-channel
:warning: This is not a channel for official support.
Please do not ping admins, moderators, or staff with Unity issues.
This is about scripting support +-
if I have Class A which depends on Class B, and B also depends on A, then they MUST go into the same sssembly
ty
and if this becomes a more complex web, then you will quickly find yourself with one gigantic assembly anyway
Isnāt it polyphormism?
no
if in my file for Class A, there is any reference at all to the existence of class B, and visa versa, then they must be in the same assembly
point being, donāt worry about assemblies, and writing code that satisfied requirements for assemblies until you get way deeper in.
So, I need to use it on bigger projects, where if I donāt do that, I would lose loads of time compiling the whole thing?
only if the project gets really big
K tysm
iāve been working on a project for 6 months. Still one major assembly. recompile is still like 5-10 seconds
i broke up a couple of smaller things into a separate assembly, and also my editor code into a separate editor assembly. Still mostly the same
If I want to control the flow orf a minigame, darts for example. Would using something like a FSM be the way to go? I feel like it would be, but I felt like I should ask just to make sure there isn't a simpler / better way to go about it
i never really found splitting asmdefs to really help compile times
i just do it for organizational purposes and limiting scopes, also unit testing
on a bigish project, it starts compiling when i hit save, generally done or close to when i swap to unity
all engines get slow while u build up the project
Unity is slow from the start
its faster then C++ compiles for unreal
Godot compiles much faster from my experience
defiently faster then any in house engine i used
have found the faster your storage the better
Do you have one of those Hot Reloaders?
Game changing shit.
my old work machine was getting pretty horrible compile times, but it was a old iMac that still had a fusion drive, instead of pure ssd. new one is ultra fast
Unreal engine hasnt been to bad from my experience with compile times either
the biggest thing that slows me down is reloading domain tbh.
and Iād rather spend an extra 5 seconds each time, than deal with the risk that build does not match edittor because i did not reload domainās static variables.
what hardware are you on?
also a big upside i have is rider tells unity to start compiling on save, so i am not switching to unity then haveing it start
rider's unity integrations have gotten so good
The fact that some Third Party treats C# better than microsoft is very effing telling
feel i get about 2 or 3 seconds on both of my machines, my mac is a M2 max 64gb ram
and my PC is a ryzen 9 7950x 64gb ram
jetbrains is just really good at making tools
i use there Rust, Go, and C ides as well
I took their Programming Course
And thats the only way i learned programming lmao. Granted it was Kotlin but the stuff they make in general is pretty good
yeah not a fan of JVM, but that aside kotlin is a cool langauge
If rider didnt have a fee i would use it
have only used it sofar for making jetbrains plugins though
ah i just have the all products pack, think it costs me like $140 CAD per year
sooo i want to use git LFS with github desktop.
ive downloaded git LFS
ive installed git LFS
and ive added all the file types i need with git lfs track "*.extentionGoesHere".
so now, i have this already existing repository on github desktop that is fully local and nothing has been pushed yet.
so if i push to origin right now, will it use git LFS, or do i need to do any more configuration?
good tools are worth the money, i spend 40 or more hours a week doing dev
Is rider even worth the price? I know it has better compatibility and features, but is it really worth it
It is yeah
It pretty much updates you about Editor Values and intergrates really well with the editor
Its one of those things where u once u have it you cant live without it
Its much better than VS
so before rider existed, i was literally running a whole windows VM so i could run vs + resharper for unity ios dev
and pretty much once rider came out i never looked back, what i use on both os's now
now comment i will make, its a total ram hog
like you will want 32gb or more for doing unity stuff with rider
I hate to be that guy, but can we move this convo to #1157336089242112090 or smth?
Yeah sorry
np, thanks š
Sorry
Sall good
dumb question, why can't I name a method '1D' ? I assume because 1D has some kind of special meaning?
Can't start things with number iirc
Ooh its the number tripping it? I see
cant start with a number, just use OneD
Ah yeah D1 is just fine
or prefix with something else
its just a parsing thing, starting with a number it thinks you are doing a literal
Also @shell sorrel and @timber comet I should apologize, I just now saw that #1157336089242112090 is a thread channel, I didn't mean to suggest it to be an ass or anything
I was using it for a dice roller like
int result = D(20) + 5; (the method was just called 'D'
Np man you are right anyway, this is a coding channel
hm I can make it XD(1, 20)
typing XD makes me feel dirty though 
hey no worries mate, topic is for programming help and we were flooding it
_1D 
Ah underscore that's acceptable
b u m p
Hello, I'm trying to make my character move like Sonic (that is, when he walks he starts slow and goes faster and faster, and when he stops he returns to his initial speed) The code works, he increases his speed etc, but it's supposed to that when you stop, your speed returns to the initial one, which does not happen
Cause you never checked when you released the button
He does With Input.GetKeyNone
You need to to use: Input.GetKeyUp()
set velocity to 5 when you GetKeyUp(KeyCode.D)
True
Oh?
I had forgotten that, thank you very much.
thx
Np
Pretty sure it's not actually possible to press the none key
Yeah lmao im so dumb for that
The reason behind that wasnāt totally wrong tho, if you press no key thenā¦
how do i uh, make 3d third person camera?
i was following a tutorial, but it got confusing mid way through
Yeah but how do you "press" no key
I can get checking GetKey, because "Are you currently pressing no key" at least makes a bit of sense
obligatory: use cinemachine
But how would you have pressed the none key this frame?
You can use cinemachine for that, with no effort you can make a third person camera
i saw it too, but how do i set it up?
You are right
look at the documentation pinned in #š„ācinemachine to learn how to use it
ok, thx
see the First/Third Person Starter Assets from Unity in the Asset Store (free), very simple examples (terrible character controller though)
Can I use the destroy method to destroy just the script that is running it?
Destroy(this);
yes
This is a reference to the script running that bit of code
Oka thxs, I just used Destroy(gameObject) up until now
also fine if you have just this one script on it
i tend to make many game objects with only one script so it's easy to pick the right one in the hierarchy by naming the game object accordingly
You can also use TryToGetComponent
TryGetComponent
Hi, can I flip the faces of an UI Image?
What faces?
Rotate it 180 on the y axis only?
Not sure why you're also rotating by 90 on the z
But if you want to flip something visually, you can set the x-scale to the negative value instead.
to make it fit into the whites squares
Ok then I'm completely missing what you're asking.
why this name appears as (Clone)? The class is a child of a general class, could it be cause of that?
If you instantiate a prefab, unity appends (Clone) to the name of the instantiated prefab instance in the hierarchy.
Object.name (which you are using there) is the name you see in the hierarchy, so if you instantiate a prefab and then set the text to be its name, that's what you see
how could i fix it?
fix what? it's not broken...set the text to be something else if you want it to be something else, or name the object when you instantiate and use that name
yes, i want to only appear the name of Allie1, without the clone
you could also create your own DisplayName property intead and use that
like a getName(){
just the camera, thx
public string Name
var instance = Instantiate(prefab);
instance.name = prefab.name;```
perfect
thanks!
Hey I'm new to unity and I need some advice
I'm making a game where you have a base, and then you can choose to explore in a randomly generated terrain, as you get either teleported to the terrain or it switches scenes
Would it be better to put the base and the randomly generated terrain in separate scenes or in the same one? My game is 3d.
If you need me to elaborate further lmk and I'll try my best
how do you check the values of a variable while running the game? i know there was a thing to put in front of it but dont remember
Break Points? Debug.Log?
yea how can i debug log
Debug.Log(someVariable)
You can also view non-local variables inside the inspector
private ones can be seen with SerializeField or Debug mode in the inspector
Same scene would provide a more seamless transition
why red?
should i write a new script for player combat or add it to my playermovement
yea System.Diagnostic.Debug
agh Debug.Log is a method.
also
You cannot use outside a method, ie where you declaring variables
that will just log the object though
if you want to see your list in the inspector btw you can serialize that
make it public or [SerializeField] private š better
I'm trying to make a main menu but am having some trouble can someone help me?
I personally keep those split up
easier to extend or debug stuff later on
trouble how?
Ok, well I am trying to get the play button of my Main Menu to go to the next scene but it doesn't really work whenever I build my project.
maybe something is blocking the button?
does it work in editor
do you have an event system in the scene
Do you have an Event System
I have 2 doors however the code i have written to open them affects both doors and im not sure why.
What do I do with it?
You just have to have it
Why onClick() dont work? (its not adding to list)
Ok I added an Event System but it's still not working
is the hovering working?
No, I don't see any hovering
put Debug.Log inside make sure is working
Do YOU have an event system? Lol
Can you show a screenshot of it?
its a Ui botton, do i need a event system?
can you screenshot your button + hierarchy
yea
Event system is for UI events
Like buttons
oh i thought with the OnClick was enough
OnClick is an event
Events are usually named "On" something
then i have a event oClick() yes
You need the EventSystem component
To make the OnClick event work
you didnt have to put on a button lol just root of scene was fine
Make sure the Button is in front of "Background"
it is it seems, lower on hierarchy = drawn last so they should be on top. Doesn't hurt to disable Raycast target on those though
Your highlight color is white...how could you tell it was hovering or not š¤ @plain mural
^ still need help
start debugging
fyi event system goes at root of scene not on button
if you disabled a gameobject button the whole canvas breaks
Which one of these is the hovering button color?
Cuz when I try it again the color doesn't change
create it from the UI menu
Highlighted color..
how do i debug that
so once i create it out, i put inside it the botton right?
start logging what it is your code is actually interacting with, never make assumptions. Visuals can be deceiving sometimes compared to what code is doing
sorry im a bit messed
Yeah unfortunately it still doesn't work
Even when I change the Highlighted Color
I wonder if the Background is covering the button?
debug the event system during playmode
it tells you exactly what you are hovering
yes, i have it there
put a Debug.Log inside the Method you call with OnClick
2 people with the same problem, no shite..
lol
There are 2 event systems in the scene. Please ensure there is always exactly one event system in the scene
UnityEngine.EventSystems.EventSystem:Update () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:543)
xD
Apparently this is what I get
well then you should only have one..
again the one added with the + button should be there only , at roo of scene
but how you connect it to the botton, once is already at root
During Playmode, You can inspect this object and tells you exactly what ur hovering
The error tells u what to do?
{
HingeJoint2D[] hingeJoints = GetComponentsInChildren<HingeJoint2D>();
foreach (HingeJoint2D hingeJoint in hingeJoints)
{
JointAngleLimits2D limits = hingeJoint.limits;
limits.min = limits.min + angleOffset;
limits.max = limits.max + angleOffset;
hingeJoint.limits = limits;
}
}
}```
Im trying to write a script where i set the lower angle and upper angle of my hingejoint2D to its original value + 180 (angleOffset) but i cant find a way to stop it from continuously adding 180 to the angle limits (it's triggered if GetAxisRaw is < 0f)
Any advice?
wdym connected to the bottom
Inspect the Event system during Playmode to see what its hitting @calm hull @plain mural
that appears when debug right?
the script
Where it says event system
ohh
you're supposed to utilize it and hover the button to see what it says
How do you access the stuff in the bottom?
click the bottom bar where it says Event System
nothing appears when hover the b8otton
thats the botton name
that means its reading whatever is on it
as UI
so that aint the issue
put Debug.Log inside your function like I said earlier and click the button , check the console
show the Attack 3 button
PointerEnter shows what ur hovering
Apparently in the bottom right the EventSystem doesn't show up
Is there something where I can show the screen?
Cuz I think it's easier to get help that way
what in the..
why do you have 2 scenes open, also remove the event system on the button..
I had the actual game in the "Home" scene and the Main Menu in the "Main Menu" Scene
Nice!!
Ok I removed the event system on the button
Navarone also already said make sure the event system is in the root of the scene
Add it from the + button and UI menu
do not put the Event System on the same object as something else with a preview and it won't be a problem. also you'd look at the preview during play mode, not edit mode
then its easier to inspect cause is its own object
Nice!!
Ur good homie
all good. Ui is confusing
with that eventsystem will be enough for all bottons right
Also you lied ? said you had changed the hover color..
I changed it offscreen
Still doesn't work though even with the Highlight Color Change
still doesnt what work? Im not inside your brain idk what u did
I added the EventSystem in the Canvas
Take a screenshot then?
The hover doesn't work
are you inspecting the Event System during playmode or what?
Hello, excuse me but can i ask a simple question?
or its in other channel
Yes I have been doing that for a bit
You can ask ur question
how can we know if there is no question..
doing what, hover the button during playmode and Screenshot the event system inspector info
xD
Screenshot ur highlighted colors...color
someone know why its blank? i tried making a new scene but nothing happends. im starting in unity but i cant get through it.
Layout -> Default Layer
also not code question, next time #š»āunity-talk
you've maximized your inspector window. Double click the header of it to put it back to normal or reset layouts
you did not follow any of the instructions given to you did you
Wdym
Where is the event system info you were asked to show
I do not. No
what
That is not what was asked for
click on it
did you not follow this
#š»ācode-beginner message
They want to see the debug information FROM the event system
And also, only ONE event system should be in the scene
Find the other and remove it
It worked! Thank you navarone and digiholic. sorry for bother tho.
And also, only ONE event system should be in the scene
Yeah only eligibleForClick changes
I already got rid of it
Ah sorry- yeah just realized
Show the actual debug info that includes what you are clicking. Most of it is cut off
See this
#š»ācode-beginner message
where are the VS settings in windows to change things like formatting?
Particularly that "Current Raycast" bit
ty
itās in a very different place from mac lol
i also see way more features in VS for windows
Is this good enough?
just keep it expanded there is no need to scroll
Yeah, no change even in hover
does your canvas have Graphic Raycaster?
the graphic raycaster will appear in inspector if you slect canvas yes ?
can u make another video with event system info expanded hovering buttons?
Ah...
So do you change the Scale of Z to make the buttons accessible?
Cuz when I delete the Background there is still no change
Event system should be a root object, I believe that was mentioned before?
Yeah I have the Event System in the Canvas Root
is anyone good with github?
Just ask your question.
I'm not sure what this has to do with Unity
ik this is the only coding server im inš
You can make a thread asking about it in #1157336089242112090, and clarify what you mean by "put up my site", it's unclear if you mean github pages
Have you... tried searching for the github discord?
i couldnt find it
do you have it?
ya github pages
thought you would make a vid of you hovering the button with event system expanded. You showed something else
Ok you know what I am just going to take a few steps back to do the Main Menu from scratch
Meaning it is the child of the canvas, and not a root object
Root object means it is a child of nothing
{
HingeJoint2D[] hingeJoints = GetComponentsInChildren<HingeJoint2D>();
foreach (HingeJoint2D hingeJoint in hingeJoints)
{
JointAngleLimits2D limits = hingeJoint.limits;
limits.min = limits.min + angleOffset;
limits.max = limits.max + angleOffset;
hingeJoint.limits = limits;
}
}
}```
Im trying to write a script where i set the lower angle and upper angle of my hingejoint2D to its original value + 180 (angleOffset) but i cant find a way to stop it from continuously adding 180 to the angle limits (it's triggered if GetAxisRaw is < 0f)
Any advice?
any general advice on how to flip a HingeJoint2D would also be appreciated
What's the value of angleOffset?
If it's the delta this iteration, it would be fine. If it's the current total amount, you need to default the limits before adding to it.
wouldnt i need to reset each of the joints manually if i default the limits of every child?
I'm assuming it's not 180 all the time.
Also maybe show what's calling this method.
yeah every joint has a varying lower/upper angle
oh its my charactercontroller script hold on
I'm assuming you're just wanting to stop it from
stop it from continuously adding 180 to the angle limits
and if the above code works then it's what's calling this method that's the issue.
The method is private so it's likely on this same script.
{
MovementState state;
if (dirX > 0f)
{
transform.localScale = new Vector3(1, transform.localScale.y, transform.localScale.z);
state = MovementState.running;
}
else if (dirX < 0f)
{
transform.localScale = new Vector3(-1, transform.localScale.y, transform.localScale.z);
AdjustAngles();
state = MovementState.running;```
oh and dirX is dirX = Input.GetAxisRaw("Horizontal"); if you were wondering
basically it just kicks in whenever i walk to the left
Without having to look at all of your code, the non-precached solution would be cs private Dictionary<HingeJoint2D, JointAngleLimits2D> initialLimits = new Dictionary<HingeJoint2D, JointAngleLimits2D>(); void AdjustAngles() { HingeJoint2D[] hingeJoints = GetComponentsInChildren<HingeJoint2D>(); foreach (HingeJoint2D hingeJoint in hingeJoints) { if(!initialLimits.TryGetValue(hingeJoint, out JointAngleLimits2D limits)) { limits = hingeJoint.limits; initialLimits.Add(hingeJoint, limits); } limits.min = limits.min + angleOffset; limits.max = limits.max + angleOffset; hingeJoint.limits = limits; } }
where you'd map the default value of each limit to each hinge joint and use those values + whatever offset you're needing to adjust.
current = initial + offset```and not```cs
current = current + offset```Where the second would do what you're not wanting - assuming you're wanting to just add an offset to the initial and not the current.
swanky, i'll check this out
question, what does the [i] in hingeJoints[i].limits = limits; mean? it's undefined
Ah, change it to hingeJoint.
Cannot implicitly convert type 'UnityEngine.HingeJoint2D' to 'int'
Had initially attempted to approach this with a different collection type.
The line should have been like your original.. hingeJoint.limits = limits;
i get an error when i remove your square brackets from that line
'HingeJoint2D[]' does not contain a definition for 'limits' and no accessible extension method 'limits' accepting a first argument of type 'HingeJoint2D[]' could be found (are you missing a using directive or an assembly reference?)
Did you remove the s as well?
How do i turn off this annoying feature that replaces the current letter or symbol instead of just adding onto the line?
Press the insert key on your keyboard
thank you! You have no idea how hard it is to explain this issue to google without sounding like a psycho
Overwrite mode
OVR
The interact function happens when you press the F key while staring at something, this whole process is suppose to open and close a laptop when you interact with it, however whenever the animation is complete, the laptop resets back to it's original rotation. Without all the coding, the laptop is closed. The animations play out normally, toggling the open and close normally, but its just resets back, im so lost and tired please help
!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.
so can you help me?
public class LaptopTurnOn : MonoBehaviour, IInteractable
{
[SerializeField] private Animator laptopAnim = null;
[SerializeField] private bool openTrigger = true;
[SerializeField] private bool closeTrigger = false;
public void Interact()
{
if (openTrigger)
{
laptopAnim.Play("laptopOpen", 0, 0.0f);
openTrigger = false;
closeTrigger = true;
}
else if (closeTrigger)
{
laptopAnim.Play("laptopClose", 0, 0.0f);
openTrigger = true;
closeTrigger = false;
}
}
well first of all is the Loop unticked on animation clip
yes, it only plays once
so what is resetting back?
im making a flappy bird type game, and the thing is you can technically go forwards with the bird because if you hit the corner of the pipes you bounce, i was trying to change that by making the bird's x position stationary, but that just makes it ignore pipes, how do i prove if the bird's on a collision? ```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BirdScriptThing : MonoBehaviour
{
public Rigidbody2D MyRigidbody;
public float flapStrength;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.position = new Vector3(0, transform.position.y); //thing where i try to make bird still
//im trying to make an if statement on collisions to see if the bird is touching a pipe
transform.rotation = new Quaternion(0, 0, 0, 0);
if (Input.GetKeyDown(KeyCode.Space) == true || Input.GetKeyDown(KeyCode.Mouse0) == true)
{
MyRigidbody.velocity = Vector2.up * flapStrength;
}
}
}```
it opens the laptop, then instantly the laptop closes
how do you call Interact
like what does the script look like?
btw you should never new a Quaternion,
why?
0,0,0,0 is hella wrong
i know
no such rotation
i was just trying to make it stop rotating completely
then disable rotation on the rigidbody
its under Constraints
yeah i noticed now
btw == true is redundant
interface IInteractable
{
public void Interact();
}
public class Interator : MonoBehaviour
{
public Transform InteractorSource;
public float InteractRange;
void Update()
{
if(Input.GetKeyDown(KeyCode.F))
{
Ray r = new Ray(InteractorSource.position, InteractorSource.forward);
if(Physics.Raycast(r, out RaycastHit hitInfo, InteractRange))
{
if (hitInfo.collider.gameObject.TryGetComponent(out IInteractable interactObj))
{
interactObj.Interact();
}
}
}
}
}
this could be god level coding or poor level, i got it off a tutorial
i know i can just ignore the == true thing, but i was following a tutorial
did you inspect the bools during runtime ? Put debug.logs also to check how many times that gets called.
if the state / bools are fine during playmode, then issue is just visuals
try to narrow if problem is animation or actual code
The code does exactly what it's suppose to do, play the animation, once the animation is does it resets back to its normal position. I've been trying for hours but I don't know how to get the laptop to stay open even after the animation plays
most likely because your animator is overriding the rotation
can you show your animator
and also screenshot the animation clips for open
Ok, so I just redid my project starting with the main menu and then with my game and it's working properly
Sorry for the trouble
no worries, at least its working now
if you want to learn more on the features -> https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/index.html
Can I use interfaces with monobehavior?
yea ofc
how can i flip the player's child object when the player turns?
sideview? rotate 180 on Y
as in add it to the playermovement script where dirX stuff is? or seperate lil one on the child?
If I run ignorelayercollision between x object and every layer in the project to blacklist all collisions, then ignorecollision false specific gameobjects to whitelist them, will that work the way i intend?
or will whitelisting specific objects like that still fail because ive ignored that layer
do you need them to be different rotation between parent n child?
uhh just mean that when i turn my player to the left in 2d game the player's attackpoint game object child isnt flipping with em
the layers are still ignored, pretty sure the colliders ignored or not would not matter to it
unless i misunderstood your question
sad
is there a semi performant way to disable all physicscollisions between 1 object and everything else via code?
idk what it iis about working with monobehavior scripts but it just totally messes with my OOP skills
switch to a specific layer that is ignored by other layers
only when needed
it's weird when the scripts themselves are kind of like objects too
not an option in this scenario unfortunately
why not
context is modding
biggest difference is that you do not new() them and unity makes instance created when is on the object
yeah, I guess that's really the only difference, but it is a big one
ermmm modding?
This code is being used on a game I didn't create
sorry community rules, we do not discuss modding / decompiled games #šācode-of-conduct
Yes I'm aware, In this specific scenario though my question isn't related to modding. You asked why I can't mess with layers for this question, that's why
well you asked for a solution and that is one of them lol
in terms of perfomance
the limitation is imposed because its related to modding š
Absolutely and I appreciate that, it's just one that isn't viable given my scenario. Think I have to play ball with the two ignorecollision functions Unity provides. That's why i was hoping it would be possible to blacklist all layers off the bat then whitelist from there
well if ignore func works then you can probably keep track of that via a collection with all the colliders, and you'd have to iterate through all of them..
mhmmmmm
myInt.ToString();
just string?
And int can be directly passed to the text property of a text object usually
As opposed to what?
idk
So why did you ask that?
MyTextObject.text = myInt
oh yeah i didnt think about that
Of course, you usually want some mix of string and values.
So this is nice too
MyTextObject.text = $"Number: {myInt}";
$
how the heck u do that? š edit: i figured it out u sneak
if i have script in ui running and i dont want to deactivate its parent game object, would it be fine to set scale to 0 instead?
why not disable the element instead
ya it took me way too long to realize it was a link
i was like tf he get that to be blue w/o the syntax block
same here
where is the disable elemtn, i have a panel and the only chek mark is beside it on top near the cube thingy
not sure where the code question is
u reference the element.. aka a Sprite for example or Image component and disable it.. imageReference.enable = false;
you can just disable the child?
or if u dont need any of hte scripts (if there are any scripts attached) just do that ^
well i mentioned running script, so if i talk about scripts in ui i dont know if they can help
if its scripting thats just using UI its still scripting and is fine to ask here š
ty
but you have some options above ^
I'll try that enable one, thank you to both. Also the script is in the panel, not in the child of the panel so there isnt a child to disable
yes but i meant Idk what you meant to do with a script, but i get it now
No donāt disable the children their too young to die
enable=false; or SetActive(false); pick ur poison
SetActive
disable the parents
now you have batman
lol
thats almost too witty š
Well I seaid before I cannot do SetActive in this case because the script is in there, if I set active to false it turns off the game object and its components which has the script
I'm trying to create a script that generates a plane with adjustible resolution, and I found a script on a youtube tutorial: https://www.youtube.com/watch?v=-3ekimUWb9I&ab_channel=ZeroKelvinTutorials
I copied the script character for character (minus the bottom bits that make the plane move in different ways), but I get this error when I press play:
Assets\Plane_Generator.cs(76,16): error CS1061: 'Mesh' does not contain a definition for 'verticies' and no accessible extension method 'verticies' accepting a first argument of type 'Mesh' could be found (are you missing a using directive or an assembly reference?)
My code is as follows:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//will create required components if not on game object already
[RequireComponent(typeof(MeshRenderer))]
[RequireComponent(typeof(MeshFilter))]
public class Plane_Generator : MonoBehaviour
{
// references
Mesh myMesh;
MeshFilter meshFilter;
//Plane settings
[SerializeField] Vector2 planeSize = new Vector2(1,1);
[SerializeField] int planeResolution = 1;
//mesh values
List<Vector3> verticies;
List<int> triangles;
//initialize mesh and assign meshFilter reference
void Awake()
{
myMesh = new Mesh();
meshFilter = GetComponent<MeshFilter>();
meshFilter.mesh = myMesh;
}
void Update()
{
//min avoids errors, max keeps performance sane
planeResolution = Mathf.Clamp(planeResolution,1,50);
GeneratePlane(planeSize,planeResolution);
AssignMesh();
}
void GeneratePlane(Vector2 size, int resolution)
{
//Create verticies
verticies = new List<Vector3>();
float xPerStep = size.x/resolution;
float yPerStep = size.y/resolution;
for(int y = 0; y<resolution+1; y++)
{
for(int x = 0; x<resolution+1;x++)
{
verticies.Add(new Vector3(x*xPerStep,0,y*yPerStep));
}
}
//Create triangles
triangles = new List<int>();
for(int row = 0; row<resolution; row++)
{
for(int column = 0; column<resolution; column++)
{
int i = (row*resolution) + row + column;
//first triangle
triangles.Add(i);
triangles.Add(i+(resolution)+1);
triangles.Add(i+(resolution)+2);
//second triangle
triangles.Add(i);
triangles.Add(i+(resolution)+2);
triangles.Add(i+1);
}
}
}
void AssignMesh()
{
myMesh.Clear();
myMesh.verticies = verticies.ToArray();
myMesh.triangles = triangles.ToArray();
}
}
In this video I go over how I procedurally generate a plane mesh with a desired size and resolution. Then I show how I use a sine wave to make it wavy in real time.
Note: While not shown in the video, I made anti-clockwise version of my triangles to be able to see the back face of my meshes regardless of material.
This other video of mine goes...
holy flash flood
i want to add +5 value to a variable once another variable reaches a multiple of 10 but i cant seem to think how to do it, can someone help me? i dont think i need to attach code since it's a fairly simple question
modulus
if (value % 10 == 0)
ive never thought of a useful way of using modulus wow
You can't spell. If your IDE has not underlined that in red you need to configure it. !ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
⢠Visual Studio (Installed via Unity Hub)
⢠Visual Studio (Installed manually)
⢠VS Code
⢠JetBrains Rider
⢠Other/None
need to compare with that after modules
ok
Yeah, added it right before you responded
Brain dead right now hahah
simple typo homie
I realize that now 
but yes do config ur IDE
ya, remainders were never really useful in school either ;D
ikr, remainders were useless after we got taught how to exactly divide any number with decimals
btw the value i was adding is now on an infinite loop once it reaches 10, it just starts adding 3 every frame
show current code
i mean in my school teachers dont really care about students
thats an actual shame
hopefully u took ur education seriously on ur own accord, well ur learning programming now soo.. must have
problematic snippet of code: csharp if (logic.points % 10 == 0 && logic.points != 0) { pipeSpeed += 3; }
if indeed
im not that dumb
at least teachers now also allow students to get help with intellisense.. also that comment u siad gonna remind alot people here how old they are
i mean im not at an age where i should be learning programming, ts should be what we're learning on informatic technology but we're apparently learning to multiply on python
where are you calling this code ?
^ can we see more context
on void update, maybe thats why
yea
how do i control it'
call it on an event when score was added
so its in update, so you would be adding to pipespeed many times
^ or in a function that runs once.. like when the score is added..
since it will keep adding as long as its still a multiple of 10
ok
so the logic that increments points should have this check and increment pipeSpeed as well when the condition is met
the thing is there are no other methods in action @ the script
well how do you add points to logic.points?
pipeSpeed is only referenced to be altered on the editor
ohhhh
collider checks
im doing flappy bird
the other approach is simple just calculating how many multiples of 10 you have
can do that with division and rounding
switch?
are you not calling a method?
no
inside collision check ?
? im a little confused myself
no would divide by 10 then floor the value back to a int
i guess
the point adding method is on another script
oh now that i think about it i can just do that there
yea
would also make it an event so other scripts can make use of it too
Mathf.FloorToInt(logic.points / 10);
would return how many multiples of 10 fit in points at its current value
then pipespeed could simply be the result of that line * 3
I need help, I have brackeys movement script right here. I wanna add something to the script that would hopefully get my character to begin a walking animation when moving
DM me if possible
use the .velocity of the character controller to drive a blend tree speed
Most people will not take the bait of DMs, and not how this srever works.
Use the speed of the CC on a blend tree.
Blendtree is part of the animator which lets you blend animations by a property such as a float value (what your speed would be)
You can blend between idle, walk and run animations using that.
Yeah, there are tutorials for it
Alrighty.
You do it by doing it. You learn it by finding a tutorial.
This is really a question for !csharp and you wouldn't change it to do that, the example is convoluted and not a usecase where you would use that capability
Join the C# Discord server, a programming server aimed at coders discussing everything related to C# (CSharp) and .NET. https://discord.com/invite/csharp
gotta love tutorials
only major difference im seeing is the reigions
(im dark mode)
most likely bad parenting / hierarchy / pivot direction
That lerp is done incorrectly (the tutorial does it wrong)

yes there's that too, you have to show where exactly your wep is in relation to camera/parent obj
The lerp thing is not a big deal though. Not part of your issue.
Just funny(saddening) how common that error is in tutorials
i forgot one silly part
ctrl + s
the lerp part didnt receive the edit for localrotation
sorry if this is the wrong place to ask.... anyone have a link to a plane cut in half model I could use? or is there an easy way to cut the plane obj in half? I need it cut corner to corner, aka into two triangles.
it is functional now, just need to fix clipping after i add the rest of the features
probuilder
you can just create a triangle
hmmm that seems like overkill for what I'm looking for.... I'll keep looking
Polybrush..
Never used probuilder before, but the alternative is to take the vertices and construct two new meshes yourself
Gotta create the vertices, normals, and UVs, pass those in
j/k just learn blender
https://docs.unity3d.com/ScriptReference/Mesh.html
Kind of a big pain, but for two triangles it's pretty simple
Something like delaunay triangulation with constrained ear clipping is much tougher š
yea could make it through code
two piece 10x10 plane
but you could do it in code..
||learn blender||
my hero
I am learning blender... the problem is that if I google "blender modify plane" I get 1000 results about aeroplanes
lol, my friends ask for little stuff like this all the time so im quick at it.. shader stuff uses simple models for all kinds of cool effects
u just need to learn the basics.. like the knife tool.. thats all i did was make a plane and cut it half and a few other things..
oh! I just figured it out myself at the same time
and why not learn how to do it code too? that'd be good to know too