#archived-code-general
1 messages ยท Page 383 of 1
oh hm, colliders use the physics engine to do callbacks, that's not gonna work for my case
guys any one online i want to talk about a tecnique used byt all games. how do they decide which task or action to perform at specific point in game ? like i have 40-50 task or action to perform how do idecide which to perform?
What tasks? Decide for who? Why?
like i have a charcter whcih has to perform multiple task like climbing pickup object rotet object dragg object ladder climbing rope clicmbing engine start action stop action lever movemnt in specify direction so how to decide which action to perform?
like 'Inside' game it has so many action to perform at specific time
Well, depends on the context...
If you interact with a ladder, you obviously want to climb, not try to start an engine.
so u mean i have to use triggerenter to perform these actions and in swithc statement i have to choose from these 40-50 actions? like 'inside' game
You don't have to use OnTriggerEnter. That would depend on your interactions implementation.
And you don't have to use switch statements. It also depends on your implementation. For example, you could use inheritance/polymorphism such that all interactions override the same base method.
As for "like 'inside' game" I've no clue what you mean. Can you do these things "outside" the game?
inside is a game by playdead.
ok i will use a base Iintractable interface and i will inherit it on all my intractable elemnts and thn perform action based on type
What? I really don't get what you're trying to say.
A base class might be better than an interface here, but I might be wrong, since I don't have the whole context.
ok i want to make a game similar to "inside" and this game has lots of actions like ladder climb door openr opject push pull rope climb edge hanging and so many action i want to decide whcih action to perform in my game. i have 5 type of switch each swithc need dirrent timing and diffrnt animation so i want to decide perfeactly.
Ah, okay. So you were talking about a different game. Never heard of it, so don't know how it works in that game.
But you most likely want to use polymorphism in your actions system.
let me explain more my game has a gameobject and my player can intreact with this game object with 50 possible ways . so i want to decide which wich way i want to intrect with this object with only one CTRL key .
That would depend on what game object that is, no?
ok stiil my question is same i want to check whcih action to perform hwo to decide . do i need swithc statement for this?
dlich do you know if unity has something like a spacial hash, or anything that will let me performatively do things like "find all nearby objects in radius"
this is what I was trying to figure out earlier with bounding boxes and colliders
if not I'll just implement one myself
it sounds like you want a state machine @normal isle
Next time add a mention wyhen you're asking a specific person.
But no. I don't think there's any system like that by default.
haha I'm not a fan of pinging people unless we're already in a conversation
if you didn't see it I wouldn't have minded either
Well, then I might've missed that message alltogether.
and that's all good
No. As I said, you can use polymorphism.
I wonder how it's possible to modify a basic spatial hash grid to be capable of lookups like
"all objects that can move"
or "all objects of a specific type"
maybe for the second one I can just have an ID associated with any object in the grid
Maybe implement it in the simplest way first, using lists or dictionaries and position checks.
You might not even need any optimizations.
I donโt think you can modify the spatial grid to do that. But you can keep hashsets of the type of objects and do a intersection with them with a hashset that is returned by the spatial query.
How would one go about building and implementing an interface similar to the built in ones like OnMouseOver that has built in triggers?
Thinking of a thing like OnEnemyDied. Right now i just doing an static event and thats great in some cases I think that an interface that have a function that triggers by default could be cleaner.
The problem is that interface methods don't implement a body so I don't understand where to put the logic
So you want magic methods like Update, Start, OnMouseOver? You'd probably need to loop through all your monobehaviors and find ones that implement your magic method, and then register them somewhere and call the method on all of them whenever an enemy dies
Ok, so there is no magic to it then. Guess i better stick to just using events then. Thought that it somehow had event subscriptions built in to the interfaces
what interfaces are you referring to? they're just methods which unity is calling for you
its not even an interface, otherwise you'd have to implement it. its reflection
there are the interface ones like IPointerClickHandler which you could replicate as well, but it's still basically the same process, just more explicit
from what you're describing, id just make a base class that has the methods you want. you can have your own implementations in the base class using virtual so deriving classes can override it.
Yeah of course. Was interested in interfaces explictly and though that the mouse interfaces seemed to do a similar thing
Yeah sorry, don't know why I wrote onmounse, my bad. What I meant was the interfaces such as IPointerEnterHandler
Or exit
Or click handler
Sorry for the confusion are trying to get my kids not to kill each other while i write. Not to good with the multi tasking
So does anyone know a bit more how those work? Is it just a loop through everything checking if the implement the interfaces or are there smarter ways?
Using GL.wireframesetting when rendering some debug stuff, I noticed it seems not possible to adjust this so that some objects are rendered in wireframe mode, and others are solid - is that right? The docs seem to suggest so too.
Looping through everything just to get around events sounds horrible.
You should really just make a base class as I said above, and in that base class do whatever subscriptions you want with the events. The stuff like IPointer sounds different from your case, at least in that case the raycast is directly targeting the objects its calling methods on. In your case, it seems like you want to be able to call this method on every instance. Im also really not sure why you just want interfaces here.
Loopigng isnt an option, mentioned that because it was suggested as a solution.
Base class would be less flexible then my current implementation so thats not an option. This is not something that I actually need I just though that it could be nice to have an interface that gives me functions that are triggered by a given event.
The IPoint interfaces are interesting to me since the implement functions that gets called without adding subscriptions.
Seems like it works for the built in interfaces since they inherit from IEventSystemHandler so that might be an option to look into
I'm not really sure what part of them you find interesting. You can replicate the exact same thing by raycasting, calling GetComponent, and then calling the method you want. Theres nothing magically about what they do
Which is entirely different and cannot be applied to calling a method on every instance of an object
Who do you do a raycast and get component with an interface? That is the interesting part. To be able to have a interface subscribe to events. Seems like you focus on the functionality; im intressted in the architechture that makes the functions in the interfaces trigger without manually subscribing
Well all objects that implent a built in interface get functions triggered without having to manually subscribe to the particular event
how to fix the variable reset issue?
Are you familiar with c# or just other OOP languages outside of unity? I feel theres a massive misunderstanding here about what the interface is actually doing.
The interface literally only declares that certain functions will be implemented on a class. It doesnt do anything else. Other classes will run logic and try to GetComponent/call functionality on your interface. Theres no subscribing here, because as I said this isnt calling a function on every instance of a script. Its directly calling the method on the object it finds.
I am making a game where you can buy weapons. You have 9000 gold and want to buy a weapon for 7500 gold and the end value is 1500. but when i buy another weapon, it starts again from **9000 **and makes it -3000 gold, cuz the other weapon costs 3000 gold
I use PlayerPrefs, but I still often get the issue
Share the relevant code
public int currentGold;
void Start()
{
if (PlayerPrefs.HasKey("CurrentGold"))
{
currentGold = PlayerPrefs.GetInt("CurrentGold");
}
goldAmount.text = $"{currentGold}/{maxGold}";
}
public void BuySwordWeapon()
{
try
{
SubtractGoldAmount(sword_prize);
if (isPurchasable)
{
buySwordButtonText.text = "Owned";
SetButtonInteractable(false);
}
else { }
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
void SubtractGoldAmount(int prize)
{
if (currentGold >= prize && currentGold != 0)
{
Debug.Log("1. CurrentGold: " + currentGold);
currentGold -= prize;
goldAmount.text = $"{currentGold}/{maxGold}";
isPurchasable = true;
Debug.Log("2. CurrentGold: "+currentGold);
PlayerPrefs.SetInt("CurrentGold", currentGold);
PlayerPrefs.Save();
}
else {
isPurchasable = false;
Debug.Log("Not enough gold to purchase this item!");
}
}
What happened between the second and 3rd logs?
the currentGold value got resetted back to 9000 gold
when i want to buy another weapon
Why? What did you do? What code ran in between?
State.cs
public abstract class State
{
protected StateMachine<State> StateMachine;
protected State SuperState;
public State(StateMachine<State> stateMachine)
{
StateMachine = stateMachine;
}
}
CharacterState.cs
public abstract class CharacterState : State
{
protected new CharacterStateMachine StateMachine;
public CharacterState(CharacterStateMachine stateMachine) : base(stateMachine) { }
}
StateMachine.cs
public class StateMachine<T> : MonoBehaviour where T : State { }
CharacterStateMachine.cs
public class CharacterStateMachine : StateMachine<CharacterState> { }
On line 5 of CharacterState.cs, an error on base(stateMachine)
CS1503: cannot convert from CharacterStateMachine to StateMachine<State>
CharacterStateMachine inherits from StateMachine<CharacterState>, while CharacterState inherits from State
Not sure what the issue is, help is appreciated 
I have googled it and its a common issue. i am not sure how this happens
It's not a common issue at all. What is the class that contains the code that you shared? What is the script attached to?
well it's a class to handle button events. the script is added as component in the button inspector
And you have a separate button for each weapon?
Yes
This are totally different issues.
Well, then think a bit. You have a field in each of these scripts that gets initialized on start. Changing that field in one of the scripts does not affect the others. Makes sense?
I have checked the discussions there and i have tried to do the same with PlayerPrefs
To save values
its lil bit better now, but still the initializing of the game makes the issue
Ah yeah could be true
So you mean that all buttons should be in one script?
Typically, you would have 1 purchase manager or similarly named script that would keep your gold values and the purchase logic would interact with it.
And where should i add the script?
i mean like where centralizing it
I usually have a single empty gameobject that contains all kinds of manager scripts.
like this you mean?
and then add the .cs script as component in the empty object?
For example, yes
Alright thanks
I can downcast with an explicit cast in C#?
is there a keyword to check if a parent class variable can be downcast successfully
is, equivalent to instanceof in other languages
afaik, you should use as instead of casts for downcasting
Yeah I been working with unity on and off for 5 years now, not really the issues. I was wondering if anyone knew how the strucutre around the built in interfaces work and how to implement interfaces that get called similar to the IPoint interfaces.
The object will be null if it cannot be downcast using as so you'll need another line for that null check.
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/is is is fine to use and you can declare the field inline too (look at the example in docs)
So bassicly how would you attach a callback to a interface function when it cant declear a body
I ask because theres literally nothing unique about it. I feel like I've described it multiple times above. theres no events, no callbacks, its literally just a guarantee that a method exists. Other code outside of your interface is doing logic and checking if your classes implement the interface. If so, they call the method on the interface, and for all they know it could literally be an empty method
Yeah I know, but how does it work?
How does the IPointHandlers functions get called?
I get that the logic is not within the interface but I still think that its a very smooth way of working and therefor I wonder if anyone knows.
How does unity know that the interface exist on that given object!? Somehow it must either have a list of all objects impelenting it or look for them right?
You can call GetComponent with an interface
#archived-code-general message
Of cousre but is that how its done with IPoint interfaces? Is the eventsystem looping over all gameobjects to see if they have that particular interface?
Hi! Does anyone know how i can handle a settings menu with netcode for GameObjects before initiating a server or join one? I'm trying to setActive(false); some buttons in the main menu when you run the game but when the function that makes the buttons not active is called it indeed deactivates the buttons but not visually only until you become a host or a client.
I'm not sure what unity does with their event system, or what interfaces we're even talking about now but the event system has it's own raycast method
https://docs.unity3d.com/2018.2/Documentation/ScriptReference/EventSystems.EventSystem.RaycastAll.html
And honestly I dont really know how this relates to your issue anymore
The answer of what logic they do doesnt matter here. The simple fact of it is they call the methods directly. You cant do this in your case unless you basically recreate what a delegate is, so you might as well just stick to what you currently have
I want to create an object that has the same settings as a component of a reference to a prefab, but this is not allowed. is there a different way to instantiate something like this?
I think thats because you think I have a issue, I have a good alternative but still Im intressted in how unity handles interally, where it lets you implement interfaces that have functions that get triggered by events without me having to subscribe to them. I get that there are other classes that subscribe and then triggers the functions of the interfaces i just wonder how it works. Where is the logic written since it of course cant be in the interfaces? Is it the coliders that looks for. Interfaces when certain triggers such as point click are met?
Or is it the eventsystem that has an array of all objects impelenting the relevant interfaces?
Components can't be instantiated, they can only be added to gameObjects.
You can instantiate the whole object with the component if you want.
So if I wanted to spawn a bunch of objects in my world but I want to make sure that the random locations I pick are not already colliding with an existing object, I need to instantiate a copy of the object and move that around?
You can make an overlap or cast check.
The source isn't public so there's no way to know for sure but the most likely scenario is that the event system fires a raycast, checks if the thing it hits has any of the related interfaces, and then calls those methods directly. This is much simpler than making arrays and triggering events.
what do you mean by these? is overlap check doing a collider.IsTouching
I dunno what cast check means
Physics.OverlapSphere and other such methods.
Thank you, that seems reasonable.
And then its easy to conclude that s similar system that involved other objects isnt really viable
ah, this doesn't need the exact collider to find collisions. I hope it's performant?
(I made a spacial hash grid for fast lookups)
There are other options with a tile system etc. You could also keep tack of the objects bounds with a dictionary with transforms and a bounds and use that when you check for collisions
I am using a spatial hash grid to store previously generated objects
No. It makes checks with primitive shapes. As for performance, you can test and profile to evaluate impact.
fair enough
I'm doing something else illegal. I have a ScriptableObject script with a GameObject variable that I put my prefab into. This prefab has a collider2d component but it looks like only the transform component is there?
actually, I think I messed up - one sec
if it's a prefab you'll have to instantiate it first
doesn't really make sense to get the bounds of an object that doesn't exist in the scene
it does in my case - I need to spawn a bunch of things in passes, and it's important that nothing overlaps. Since there's no actual guarantee that any spot I sample in the world can fit the object, I think it's more elegant to check the bounds first before instantiating it
oh just getting the size of the collider? misunderstood that, mb
yeah all good, i am usually bad at making myself clear
but how are you defining the bounds as a Vector2?
it looks like Physics2D.OverlapBox takes "size", which I think is not extents.. just the width/height
I'm not 100% actually
what if it isn't a boxcollider though
any Collider2D has bounds
I am just taking the extents
I didn't actually need to downcast
i mean, if it's not a boxcollider, a boxoverlap check would be inaccurate
Yeah thatโs true
I guess I still need the actual collider somehow
Is it a 2d game?
Yes
Are you using polygon colliders with very custom shapes? Otherwise i think box collusions should be good enough
I plan to hopefully get pretty precise, so ideally yes
if they have rigidbodies you could just let them overlap and fix themselves
Not necessarily
You could also do it in two steps, first check with box and if that works spawn and check with real colliders
In that case it will be a fast check in 99% of the cases but with a safety for the odd cases
I only really need to get a Collider2D in my code so I can use it to check against other colliders
(also consider if you have multiple colliders)
true, in which case I can probably get all collider components instead
but I'll worry about that later
Yeah but if you need the exact collider you need to instanciete it or a proxy with the same collider
yeah if that's the case then so be it
would it lead to performance issues if I instantiate a prefab and change it's position for each potential spawn point, for potentially a hundred different prefabs with thousands of locations
nah actually
the work would be in instantiating the prefab, and the physics check
I can instantiate an empty gameobject with a collider with the same settings as the prefab right
doesn't have to include anything else
if you're using a separate prefab then that seems like a pain to deal with in the future
well no, something like this
and then just delete collisionChecker when I'm done with this prefab
If the object is disabled, there should be no additional overhead with changing the transform, otherwise if it is enabled, it will cause the parent its a part of (or the scene hierarch if its a root) to be "dirty" and recalculate the next frame
consider this, still
maybe check for a composite? idk
or i guess always have the composite first, if you can remember that, but that sounds like a future headache
can I still do collision checks with its collider if the object is disabled
I guess it doesn't actually matter here because all of this is done when the world is generated and only once
Also I dont think you can do this, because Collider2D is not a component that can be added to an object on its own, whatever inherits it can (for example: BoxCollider2D), youd have to know or check the type, which may provide different properties to add... There may be a way to "clone" the component, though I cant recall the API and if its editor-only atm
If your doing the AABB calculation yourself, yes, otherwise it would need to be enabled for the physics system to consider the collision AFAIK
hmm okay
I think I will just spawn a temporary prefab and move it around for collision checks, seems the simplest way at this point ๐
anybody know why my UI elements remain drawn even if i use the setActive(false); function?
I m using netcode for gameObjects
when i move them there are 2 images of them one where it previously was and one where i currently moved it
happens in Game scene
the buttons get deactivated in the left hierarchy but don't disappear from the screen
the buttons disappear if i create or join a game
but i want to be able to make a settings menu
i also tried redrawing the scene didn't workj
work
with sceneview.repainall();
has anyone encountered the problem with rigidbody2d's MovePosition where your character auto moves to the right
you're probably gonna have to elaborate
ever since i changed from transform.position = to .MovePosition
my guy just flies off to the right
here's my forum post https://discussions.unity.com/t/my-guy-is-auto-moving-right/1546843
maybe i should use addforce instead?
public GameObject car;
public GameObject cameraPos;
private float speed = 0;
public float defaltFOV = 60, desiredFOV = 90;
[Range (0, 50)] public float smoothTime = 8;
private void FixedUpdate () {
follow ();
}
private void follow () {
speed = car.GetComponent<Rigidbody>().velocity.magnitude / smoothTime;
transform.position = Vector3.Lerp (transform.position, cameraPos.transform.position , Time.deltaTime * speed);
transform.LookAt (car.transform.position);
Camera.main.fieldOfView = Mathf.Lerp (Camera.main.fieldOfView, defaltFOV, Time.deltaTime * 5);
}```
anyone know why my car is tweaking like that
have you tried using LateUpdate instead of FixedUpdate
so it actually changes every frame
actually the background seems smooth, so maybe it's an issue with how your car is set to move
You don't need to use fixed update if you don't use physics. Bother the car movement and camera need to be updated in regular update.
hi, im currently having an issue with my navmeshagent where in editor game testing he works perfectly fine and there is no issues. but as soon as i build the game he refuses to specifically see me, he does everything else fine but his sight mechanic wont work i have no idea why ive never had this issue when building. ive checked the console in game too but that isnt giving me any errors.
sight script - https://pastebin.com/1iTytLMY
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.
also detecting if the agent is in the camera view just in case it has something to do with the screen size or something - https://pastebin.com/KauDDLA1
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.
Debug your code rather than just trying to guess what is wrong
again, it works perfectly fine in the editor so im not sure what to even debug
everything
ok?
Where can I find assets for making a small 3d horror maze game?
this isn't a code question now is it?
google around.
asset store. etc
No.
Iโm using ChatGPT to help me make it.
so why are you asking asset questions in a code channel ?
also GPT is not going to help you do anything but copy and paste, when something breaks. You won't know how to fix it
how is that relevant, or did GPT tell you to ask here?
Iโm looking for the general chat.
try reading the description of the channels then..
id:browse
Hi all,
I switched to the new input system to tackle gamepads / controllers better. While most things are fine, I noticed two areas with issues --
- I have auto-swtiching on between the mouse / keyboard and the controller. It looks like using my mouse cursor is fine, but when I switch to the controller, there is some kind of strange secondary cursor that shows up. However, the mouse cursor is rendering the correct glyphs over my hotspots, but that is stationary.
I've attached a video here just in case, if that would help!
quick question: is the resource usage of code execution in the editor when using the [ExecuteInEditMode] attribute the same as runtime?
define "resource usage"
how well the application runs... i think?
in the vast majority of cases they won't be running on the same device so it's all relative
plus ExecuteInEditMode works very differently from runtime in terms of how often Update runs, etc.
i dont really understand what you mean by this
generally "resources" people are thinking about are CPU time, memory, etc.
when a player downloads and plays your game it won't be done on whatever computer you are developing the game on
i guess what i meant to say is performance
it's on their computer, or phone, or xbox or whatever
no
if you want to test performance you need to make a build and profile the game on the target hardware.
ah ok i understand what you mean now
im not looking to test performance, im just wondering if editor code execution will be AS performant as runtime code execution
i suspected this to be the case but wasnt 100% sure. thanks for the insight!
The other issue is -- it looks like I'm unable to click on TMP_InputFields correctly anymore.
This worked on the old input system, but I have a hunch that due to the new input system, the mouse position is somehow not being read correctly?
This doesn't work on controller, nor does it work on regular keyboard / mouse anymore.
I tried looking up this issue, but I couldn't find any threads regarding it, so I just wanted to ask here in case anyone else faced the same issue when switching over to the new input system.
Any guidance / help is appreciated, thank you!! ๐
there is a color change, which suggests it is being clicked, so maybe try listening to some events and see where it's going wrong
Hey!! Yes!
So the thing is, it looks like I have to move my cursor in a strange position in order to change the text.
Would the input debugger be the best way to go about this?
I'm not very familiar with it since so far I was relying on the old input system, but I'm not sure if that would help log events from various devices
the input debugger would let you see if the "click" action is being received correctly, but i don't think it'll help if the issue is with detecting the click on the inputfield specifically
so maybe try to deduce which part is going wrong (receiving the click vs selecting the inputfield) and go from there
Gotcha!! So just debug log statements in some kind of "on click" script
Thanks for the heads up! :))
right, and also check the input debugger for the first part
Do you guys know why this wouldn't be working? My object that I have in the scene is tagged "Lever"
what is "this"? We don't know what you're debugging
Just using a switch statement:
string colliderTag = collider.tag;
switch (colliderTag)
{
case "Player":
NetworkObject networkObject = collider.GetComponentInParent<NetworkObject>();
// Punch
PunchServerRpc(networkObject.NetworkObjectId);
break;
case "Lever":
Preusmably that collider is not the collider from your first screenshot
it's a different one
Sorry, it's reading "Untagged" for my object rather than "Lever", which it is tagged in within the scene
Yes and I'm telling you it's a different object
Gotcha! Thanks!
I think I might be missing it, but do the logs show up under one of these?
Yeah that'd be easy, and maybe it is, I guess, But I do a sphere check to gather all the colliders in an area, and when I loop through them, it's that "Sphere" object
I guess I can name is something more obvious to confirm
how do you know it's that sphere and not a different sphere
Im making a multiplayer game with URP, i need to remove a URP camera, sadly it displays an error that says i cant remove it because universal additional camera data depends on it. Tried to remove the whole gameobject also doesnt work. Any solutions?
should be UI/Click
Tried to remove the whole gameobject also doesnt work
How so? What happens?
Awesome, thank you so much!! ๐
it displays the error "cant remove camera because universal additional camera data depends on it" cs // Your code here Destroy(GetComponentInChildren<Camera>().gameObject); NOTE: in Built in render pipeline it fully worked
Ahh interesting, it looks like nothing is happening there -- so is there a setting I would need to enable?
Tried to scour online but the closes thing I found was this -- https://discussions.unity.com/t/code-to-fix-tmp_inputfield-to-support-new-inputsystem/774250
I'm not sure if this is actually relevant here, but my active input handling has the new system only, as opposed to both
you sure you saved your code?
Or you don't have another line of code destroying the camera component?
120% sure
show the full code and full stack trace
I'm not sure if this is actually relevant here, but my active input handling has the new system only, as opposed to both
that's correct, you shouldn't have both
whats a stack track
Ah perfect!
i think that's just debugging what devices are under what actions? i was wondering why it wasn't familiar
the stack trace is the part of the error message that shows the full callstack
there should be a different one for debugging detection
Thanks for the heads up on that front -- sorry for all the questions btw -- was relying on the old system so far, since i'm making a point-and-click game haha, but a couple of people mentioned they would like controller support / steamdeck verification, so started looking into this XD
Ahh hmm I see
This part here that shows where in the code everything is happening
oh!
So just the regular console?
(I expanded the debugs above but couldn't see anything pertaining so was just wondering)
ohhhh thats what its called? one second to export the build again just to make sure(need to run it on another client)ลพ
For resolution's sake: it was indeed the right sphere, however, I was using a prefab, and while I changed the object in the scene, I didn't change the tag of the prefab. Not sure why that mattered (maybe a bug), but it works now that I've changed the prefab's tag.
sounds like you have a reference to the prefab instead of the sphre in the scene
Yeah I'm not sure what my artist did, so that may be the case. Thank you anyway ๐
log file:
Can't remove Camera because UniversalAdditionalCameraData (Script) depends on it
same error in editor, didnt see it
and the stack trace...?
its just : Can't remove Camera because UniversalAdditionalCameraData (Script) depends on it
that doesn't make sense if you're destroying the GameObject
the answer is obvious
destroy UniversalAdditionalCameraData first
show the full code
well yes you can do that^
but regardless the error doesn't make sense if you're destroying the GameObject
You probably left the other code in or something
@wheat elbow in the Input Debug menu, go to the Devices dropdown, and double-click one of the devices there
at the bottom of the new window, there should be a log of events from that device
Also just updated to 3.0.9 in textmeshpro just in case, not sure if that would help -- looks like I'm still facing the same issue but hopefully being up to date helps haha.
Ah! Will try this, thank you so much! ๐
i might have found the problem, testing it now, a script looks like it showed an error in editor that otherwise didnt show in the built game
wepon sway to be exact
So it looks like when I'm clicking down, the number of logs do increase for sure
tried to click a few times just in case
so it seems like it's registering the lick
*click sorry
but I'm not sure if that would correspond somehow to it being correctly read into the TMP_InputField
yep, that fixed it, wierdly the built game didnt show the error, although now i have a different error to fix lol
They all seem to have similar things
anyways sorry for spending your time on a dumb mistake, thank you @leaden ice โค๏ธ
Not sure if this would help, but here's an example of one of my TMP_InputField components
it was working before the update, but I suspect that the cursor reading would be different, hence why it's not selecting as expected?
This is also my event system prefab that spawns in every scene, if that would help!
that part should be fine then, try the debug logs in events then i guess
never mind, didnt work
yeah makes sense, I'll just create a mock script for now ๐
Ahh ok
interesting
so when I click on it, and the cursor doesn't show up -- it does register a select AND a deselect!
But let's say I do click on it, and the cursor does show up, then it only registers a select
I don't understand why it's auto-deselecting, very strange
For reference, this is the script I attached to one of my input fields as sanity:
using UnityEngine;
using TMPro; // Make sure to import the TextMeshPro namespace
public class FauxScript : MonoBehaviour
{
public TMP_InputField inputField;
void Start()
{
inputField.onSelect.AddListener(OnInputFieldSelected);
inputField.onDeselect.AddListener(OnInputFieldDeselected);
}
void OnInputFieldSelected(string text)
{
Debug.Log("Input field selected");
}
void OnInputFieldDeselected(string text)
{
Debug.Log("Input field deselected");
}
}
Also when I hover over it, and even if I stay in the same position while the caret blinks, it fires a "select" AND "deselect" event.
Strangely, it looks like none of them are after updating to the new system ๐ฆ
Granted, it's not like they are fully unselectable, but the user has to move their cursor to a weird position, which seems quite inconvenient haha
Thankfully there aren't many places with input in my game, but yeah it seems like all of the fields have the same issue from when I tried it yesterday ๐ข
not sure what to check from there tbh, maybe try asking in #๐ฑ๏ธโinput-system (with this new info of course)
Omg -- I totally missed that channel haha -- thank you so much for pointing that out!! ๐
In the process of creating a unity forum thread as well, so I'll paste that there for context.
Thank you so much for all your help through this btw -- really appreciate it! ๐
Everytime I re open my project one of my scriptable objects has this error on it. No idea why, any suggestions?
[CreateAssetMenu(fileName = "ShurikenFactory",menuName = "WeaponFactory/Shuriken")]
public class ShurikenFactory : WeaponFactory
{
public override IWeapon ProvideWeapon(IWeaponParent parent)
{
return new Shuriken(parent,data as ThrowableWeaponData);
}
}
Fix your compiler errors
there arent any
Show the console. Also is the script name the same name as ShurikenFactory? data does look to be in this script either, unless it is in an inherited one.
public abstract class WeaponFactory : ScriptableObject
{
public WeaponData data;
public abstract IWeapon ProvideWeapon(IWeaponParent parent);
}
}
Yeah data is inherited and the script names all match, if I go into the script and save any changes it works again, so its not a big deal just kinda annoying to have to do that every time I open the project
Hm, how do you make the SO?
Just through the normal Create, Weapon Factory then select Shuriken
Strange, was wondering since I've seen some "fake" compile errors when you make an SO in a scene and fail to save as an asset properly, or if the SO type is in a dll/editor folder. But if you are making it via the normal menu, then I'm not sure.
Yeah weird, whatever its not a big deal ill look into it more
before you open the project again, check to see if the meta files for both the SO instance and the script file exist, and make sure that in the .asset file for the SO instance it shows the correct guid for the script (it will be in the m_Script property) and the script's guid will be in its meta file
fileFormatVersion: 2
guid: 2bd81912af68ff04a9139be98f025412
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
i see this in the SO asset.meta file and this in the actual cs script meta file
fileFormatVersion: 2
guid: d952149306f44165a51a1a32a0101f8b
timeCreated: 1730501946
are the guids supposed to be matching?
No, the matching one is in the SO instance's .asset file like I said
I tried doing it this way, and I quickly found out that the angle difference I get is completely useless, because all local rotations change in unpredictable ways (due to transform.LookAt()) making it impossible to infer any kind of angle difference between two joints directly.
What I ended up doing was to create a triangle of the positions of the joint, its end-effector, and its parent and then comparing the angle at the joint on both rigs. So, basically your method A twice and then compare the results.
can someone help me? im making an gorillatag fangame and its not building anymore
i already reinstalled photon vr but nothing works
why do you have Photon in a resources folder?
its got installed there
then maybe you should ask Photon why they do that if it will not build
i fixed it now
I don't know why this wouldn't work but
IsTouching is not true for these two colliders
am i missing something?
Did you make sure to read the notes in the documentation?
I found this page before but it's not super descriptive
originally I thought it was because isTouching was returning false always because there hasn't been a physics update yet
but here I am putting it in FixedUpdate() which means there should have been a physics update
https://docs.unity3d.com/ScriptReference/Collider2D.IsTouching.html
you can find the exact pages by just googling the exact name. "collider2d is touching unity"
oh yeah I read that too, but there's nothing it in that implies what i'm doing will not work
...as far as I can tell
So it returns false on the consecutive updates as well?
does it always return false, for more than 1 fixed update?
yes, I put a breakpoint in the debug log too and it's never hit
maybe play with the ContactFilter2D overload to see if you can get any contacts
I continue to have nav mesh problems in the unity asset game creators.
Does anyone know how to solve this aside?
!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.
that looks so wrong.
It's defining the same class twice in the same namespace and the comma at the end of line 21 makes no sense
I know I was altering it around, and the concept of it continued to halt me of starting my project with the provider.
ah, I see a forum post that says that for 2d the physics engine only cares about collisions between a rigidbody and other things?
yes, rigidbodies are what drive physics
If your two colliders don't match in the matrix you won't get physics messages.
you do need a collider as well
the rigidbody handles physics, the collider defines the bounds of the object
they work together
yeah I get it now
if I need to wait for physics updates to check if something overlaps then it's not the correct approach for me
you don't though, you can use casts to check for colliders
For 3d as well.
Colliders without rb secretly belong to one hidden static rb actually.
oh, so objects without an rb would use the static rb column?
Yeah. It might be an overstatement, but iirc that's how the physics system treats them under the hood.
can you elaborate on this?
Casts and overlaps. I think that has been suggested many times to them...
you're prolly right, I'm just confusing myself by trying to do use many new concepts at once
so thanks for being patient
have you checked that their layers are allowed to touch, they have rigidbodies, etc?
and if there's multiple colliders where you might be getting the wrong one
but if they're simple you could use casts instead which do the checking when theyre called
problem was that i didnt add rigidbodies
so a BoxCast doesn't need physics updates to find colliders?
yeah
do my prefabs also need a rigidbody for the BoxCast
A BoxCast is conceptually like dragging a box through the Scene in a particular direction. Any object making contact with the box can be detected and reported.
not sure.
for physics casting only a collider is required. A Rigidbody is required for collision and trigger events
Difference between radius and maxHeight? I don't get it
Doesn't SphereCast just make an invisible sphere and if it collides with something, return that info to hitInfo? What do we need a maxHeight for?
There's no maxHeight. Do you mean maxDistance?
Yeah; my bad
Spherecast makes an invisible sphere and moves it towards direction, like throwing a ball
You are confusing with CheckSphere
The radius parameter is the size of the sphere. The maxDistance parameter is how far the sphere should travel in the given direction.
But what's the maxDistance?
Wait; what do you mean by travel?
Do you know what it does in normal raycast?
Yes
The distance it is allowed to travel until it hits something
It's the same thing here
By default this is basically infinite
So I can leave it at something like -1? And itl be infinite?
You can not specify the parameter and it will be infinite
See the docs you linked. You use Mathf.Infinity for infinite distance
IDK how it would respond to negative distance
I'm making a player controller and the player walks fine when walking backwards but barely moves when trying to walk forwards. Could anybody help? (video attached for reference)
please post !code correctly. Use a paste site
๐ 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.
Sorry! I'm new here.
https://hastebin.com/share/wozonilebi.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
why the * Application.targetFrameRate?
to correct the time.deltatime
yeah it's basically just 1 then
yeah
don't know where you got that code from but it makes little sense.
the delta calculation is very strange and not necessary.
for some reason you calculate mouseInputVector twice the second overwriting the first
you use your strange delta calculation in AddForce which is already frame independent
it's negating the effects of using deltaTime to begin with
physics stuff should probably be in FixedUpdate anyways
indeed, I missed that one
wdym by that second one? not seeing any overwriting
moveInputVector = new(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
mouseInputVector = new(-Input.GetAxisRaw("Mouse Y"), Input.GetAxisRaw("Mouse X"), 0);
those are separate vectors
my bad
what's with the drag calculation?
rbs already have a field to handle that
make sure your input axes are correct, try logging moveInputVector to see if it's what you expect, just to narrow it down to either the input or the physics
what could be causing neither of my debugs to print? i have the script and a capsule collider on the same object but nothing pops up in the console
{
if (other.CompareTag("PlayerTrigger"))
{
print("In range of player and attacking");
animator.SetTrigger("Hit1");
}
else
{
print("Not in player trigger");
}
}```
the method is not being executed
yeah i see that, but what could be causing that
missing rigidbody, colliders not marked as triggers, lots of other things
oh, i forgot the rb... thanks
-The * Application.targetFrameRate is weird and incorrect
-Mouse axes are already framerate dependent, don't multiply it with deltaTime in TurnCamera
-Continuous forces should not be added in Update but in FixedUpdate instead
-Forces should not be multiplied by delta time
I draw a ray from my main camera to my mouse position like so
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
But for some reason, the ray.origin keeps changing, even though the camera does not move, what am I missing?
it's not a ray from the camera to the mouse, it's a ray from the mouse through the camera into the scene
the ray.origin is just where you clicked
hmm, so should the ray distance still be the distance between camera and clicked point?
no, the camera position isn't really relevant to the ray
the camera just provides a screen, the screen is then mapped into the world
the ray is orthogonal to the plane of the screen
ah I think that's what's wrong then, I'm trying to use ray origin and hit to determine which object should be selected, but i should probably use distance from camera after the raycast logic instead?
object selection
it's that convoluted because it's raycasting on objects without colliders i believe
ah, so no physics, rip.
if you don't have colliders, what did you mean by "hit" here?
You believe? You should know. Just look at the objects. If they don't have colliders then why are you raycasting? That only works with colliders . . .
uhh pretty sure the "i believe" is applying to the "it's that convoluted because"
If you're not using colliders, then you need to check the distance between each object and the camera . . .
yeah it's something using the mesh
i think the simplest thing for now is to keep using the whole "ray on mesh" thing but disregard distance from it to decide which object to select, just go through all the objects hit by the ray and calculate distance from camera to determine which one to select
the simplest thing would probably to use colliders, no?
it's a map editor so not every object is expected to have a collider
I'm back again. although a BoxCast or CircleCast can check against colliders, it looks like right now that it won't check against a collider's new position if I change it (and there hasn't been a physics update yet).
you can call the SyncTransforms method, though be aware that method can be costly depending on the number of physics objects in the scene
otherwise, yes you are querying the current state of physics which means anything moved since the last fixedupdate will not have updated in physics yet
I see... I would probably have to call it n times for n objects
because I'm placing the whole world's stuff one by one
you just need to call it once after all the things move
but hwat are you actually doing here?
I'm procedurally generating everything in the entire world
If this is just some grid based thing, you shouldn't use physics at all
it's not grid based
it's like this: I have a list of prefabs and some spawn conditions
- for each prefab, generate a poisson disk sample
- spawn the prefab at the sample points ONLY IF it doesn't collide with something already spawned
yes, but I have multiple passes
save the results of earlier passes
use a single poisson disc arrangement for all passes
it's not obvious how I can use a single arrangement
my objects all have different densities based on location and whatnot
do they have different sizes though
yes
I'm spawning everything, that means trees, rocks, big structures, small flowers, I need the flexibility
I would probably do something along the lines of:
- Generate the poisson discs at a high resolution
for each object layer:- generate random spawn positions
- snap them to the nearest poisson disc
- mark all overlapped poisson discs as occupied
For later layers if you try to spawn something and it overlaps an occupied poisson disc, just don't spawn it.
kind of inspired by the way mapmagic does things
MMWG (http://u3d.as/oDY) wikis, issues, and most recent patches and betas. Plugin Tools are required along with this repository to make MapMagic...
let me take a look at this
but I think it's hard for me
actually.. hm.
you mean I should check against all the previous poisson discs if it overlaps them? that sounds expensive
another alternative I think is to use a spatial hash grid and use a custom boundary implementation that doesn't need to interact with the physics layer (which would prevent lots of expensive calls to SyncTransforms)
I'll sleep on it 
GetComponentInParent does'nt work๐ฅบ
yes it does.
Can someone help me? IT seems like my character moves for a couple miliseconds after I released the input
private void GetMovementInput()
{
float x = PlayerInput.MoveX();
float y = PlayerInput.MoveY();
IsRunning = MovementInput.y > 0.0f && PlayerInput.Run();
CurrentSpeed = !IsRunning ? m_MoveSpeed : m_RunSpeed;
m_MovementInput = new Vector2(x, y);
if (MovementInput.magnitude > 1f || MovementInput.magnitude < -1f)
m_MovementInput.Normalize();
CurrentSpeed *= 0.1f;
}
private void UpdatePlayerMovement(Transform transform)
{
if (m_CharacterController.enabled)
{
Vector3 vector = transform.right * MovementInput.x + transform.forward * MovementInput.y;
m_MovementDirection.x = vector.x;
m_MovementDirection.z = vector.z;
if (MovementDirection.x > 1f)
m_MovementDirection.x = 1f;
if (MovementDirection.x < -1f)
m_MovementDirection.x = -1f;
if (MovementDirection.z > 1f)
m_MovementDirection.z = 1f;
if (MovementDirection.z < -1f)
m_MovementDirection.z = -1f;
m_MovementDirection = MovementDirection.normalized * CurrentSpeed;
bool flag = false;
if (m_ActiveGravity <= 0.0f && m_CharacterController.isGrounded)
{
m_ActiveGravity = 0.0f;
m_MovementDirection.y = -0.27f;
}
else
{
m_ActiveGravity -= m_Gravity;
m_MovementDirection.y = m_ActiveGravity;
}
CollisionFlags collisionFlags = m_CharacterController.Move(MovementDirection);
if (collisionFlags == CollisionFlags.Above && m_ActiveGravity > 0.0f)
collisionFlags = m_CharacterController.Move(Vector3.up * -0.01f);
}
}
}
Depends on how this works: PlayerInput.MoveX();
probably it's coming from there
public class PlayerInput
{
public static float Sensitivity = 1f;
public static bool HasController { get; private set; }
public static bool IsInverted;
public static float MoveX() => GetInput(GamepadInput.GetAxis(InputControlType.LeftStickX), Input.GetAxis("Horizontal"));
public static float MoveY() => GetInput(GamepadInput.GetAxis(InputControlType.LeftStickY), Input.GetAxis("Vertical"));
private static T GetInput<T>(T inputKeyboard, T inputGamepad)
{
T obj = default(T);
if (!inputGamepad.Equals(default(T)))
{
HasController = true;
return inputGamepad;
}
if (!inputKeyboard.Equals(default(T)))
{
HasController = false;
return inputKeyboard;
}
return obj;
}
}
Do you see anything wrong? Genuine question
It's because you're using Input.GetAxis
GetAxis has smoothing built into it
Use GetAxisRaw if you don't want that
Oh okay, I see
why do you go to all the trouble of calculating m_MovementDirection and then not use it?
I do use it, I just had to cut it off because discord said the code was bigger then the word limit
then use a paste site to post code correctly. but you controller.move does not use it
see? ```cs
private void UpdatePlayerMovement(Transform transform)
{
if (m_CharacterController.enabled)
{
Vector3 vector = transform.right * MovementInput.x + transform.forward * MovementInput.y;
m_MovementDirection.x = vector.x;
m_MovementDirection.z = vector.z;
if (MovementDirection.x > 1f)
m_MovementDirection.x = 1f;
if (MovementDirection.x < -1f)
m_MovementDirection.x = -1f;
if (MovementDirection.z > 1f)
m_MovementDirection.z = 1f;
if (MovementDirection.z < -1f)
m_MovementDirection.z = -1f;
m_MovementDirection = MovementDirection.normalized * CurrentSpeed;
bool flag = false;
if (m_ActiveGravity <= 0.0f && m_CharacterController.isGrounded)
{
m_ActiveGravity = 0.0f;
m_MovementDirection.y = -0.27f;
}
else
{
m_ActiveGravity -= m_Gravity;
m_MovementDirection.y = m_ActiveGravity;
}
CollisionFlags collisionFlags = m_CharacterController.Move(MovementDirection);
if (collisionFlags == CollisionFlags.Above && m_ActiveGravity > 0.0f)
collisionFlags = m_CharacterController.Move(Vector3.up * -0.01f);
}
}
and you use it there where?
I declare a public Vector3 MovementDirection that points to m_MovementDirection
[Header("Movement")]
private CharacterController m_CharacterController;
public float m_MoveSpeed = 0.5f;
public float m_RunSpeed = 1f;
public bool IsRunning { get; private set; }
public float CurrentSpeed { get; private set; }
[SerializeField] private Vector2 m_MovementInput;
[SerializeField] private Vector3 m_MovementDirection;
[SerializeField] private float m_ActiveGravity;
[SerializeField] private float m_Gravity = 0.02f;
public Vector2 MovementInput => m_MovementInput;
public Vector3 MovementDirection => m_MovementDirection;
which you conviently do not show, hence the need to use a paste site
Oh yeah, pastebin doesn't have a limit, does it?
no idea, you're the one pasting code
I'm using an asset pack that has different material variants for different faces. I want to make a generic script I can put on my objects to "animate" the faces by switching materials but I don't want to assign them all for each object. So I want something like "static" Meterial references in my script. I can't assign them in the inspector. How would you do it? (I can introduce a "manager object" that has the material assigned and reference that, or I could initialize the static vars via code (I'd hardcode the paths to the materials - do I need them in the resources folder for that?)
You could make a ScriptableObject with all the references
create one instance of it
and have all the scripts point to that one SO
Would this be a good or "bad" method of creating inputs? I'd like to have an expandable method but I'm not sure if this is taboo
I did just try a dictionary to store a string and Key but apparently Unity doesn't serialize dictionaries
why would it be taboo
looks ok but are you sure you want GetKey and to allow multiple keys?
the taboo thing here is actually the use of AddForce in Update. AddForce, like most physics stuff, belongs in FixedUpdate only.
Ah good point actually, I did know about that 
Not sure I understand, is GetKey not the correct thing to be using?
getkey fires every update it is held, getkeydown only fires once
That is what I want 
that will be adding a lot of force over a very small time period
It's fine if you're looking for a continuous acceleration - e.g. a rocket engine
Motion seems to be smooth and steady at 10 on the z axis, I can cross a 100m plane in 10 seconds which is what I'm aiming for
I think I see the problem with jumping lmao
As you are using GetKey and are happy about that then you can probably move the whole code to FixedUpdate, it's actually not a bad solution in all
maybe use GetKey for Force/Acceleration and GetKeyDown for Impulse/VelocityChange
Yup, I set up two lists for different inputs, should be able to add mouse and single use things to the singleInput list 
though you'll need to use Update for GetKeyDown since inputs are bound to that
with GetKey since it's a continuous action it'll work fine in FixedUpdate, but GetKeyDown will be true for 1 frame, so that won't handle correctly in FixedUpdate
If I'm only running the jump code once, then waiting for the player to make contact with the ground, I should be fine to apply the force in Update correct?
no
well sorry
you mean a one-off impulse force/
Yeah that will be ok in Update
Ya
It worked pretty nicely, I am surprised how simple a character controller is. A few months ago I would've spent a few hours on this ๐
lol, you wait untl you start hitting edge cases and then come back
how simple a character controller is
Ehhhh it's simple to get something working but it's generally complicated overall
wait till you want to enforce a max speed, or handle crouching, or a million other things
or smoothing
@young tapir But anyway, don't listen to us old farts. 10/10 for effort
How can I do math on this so its kinda like a deadzone? The more you go, the faster you get? And then when you let go of the joystick, it resets?
public static float LookX() => GetInput(GamepadInput.GetAxis(InputControlType.RightStickX), Input.GetAxis("Mouse X"));
public void GetInput()
{
m_MouseX = PlayerInput.LookX() * PlayerInput.Sensitivity;
m_MouseY = PlayerInput.LookY() * PlayerInput.Sensitivity;
}
public void Rotation(Transform character, Transform camera)
{
m_CharacterRotation *= Quaternion.Euler(0.0f, m_MouseX, 0.0f);
if (m_UseHorizontalRotation)
m_CharacterRotation = ClampRotationYAxis(m_CharacterRotation, -m_HorizontalRotationValue, m_HorizontalRotationValue);
character.localRotation = m_CharacterRotation;
if (camera)
{
m_CameraRotation *= Quaternion.Euler(m_MouseY, 0.0f, 0.0f);
if (m_UseVerticalRotation)
m_CameraRotation = ClampRotationXAxis(m_CameraRotation, -m_VerticalRotationValue, m_VerticalRotationValue);
camera.localRotation = m_CameraRotation;
Vector3 localEulerAngles = camera.localEulerAngles;
localEulerAngles.z = 0.0f;
camera.localEulerAngles = localEulerAngles;
}
LockCursor();
}
I just want it for the rightstick though, not the mouse
a character controller can be made in thousands of different ways. I spent a whole day on mine because I decided to use velocity smooth damping and a first person cinemachine camera. It works great though, so I'm proud 
HI! I would like to ask some help. If I have elements in a list. I create an instance from every list element using a prefab. How can I find the i element prefab from the list. For example I am searching the third prefab? Thanks a lot
list[2] ?
If I have elements in a list
What is the list? A list of prefabs? A list of instancescreated from prefabs?
I create an instance from every list element using a prefab
So a list of instances crewated from a single prefab?
How can I find the i element prefab from the list
What is an "element prefab"?
Are there multiple prefabs? Your question is confusing.
nope. For inventory system. I store the items in a list, and I draw a gameobject prefan on the canvas. I am searching the third item on the canvas
the third item in a List is index 2
I attached a prefab for every element and I stored them in an Item type list
what do you not understand about what I said?
I draw a gameobject prefan on the canvas
Sounds like you are creating an instance of a prefab for each item in the inventory
you need to be precise with your language here. The things you create with Instantiate are not prefabs
the source object is a prefab
the thing it creates is an instance of the prefab
the yellow one is the prefab for the sword, If I attach it, it working, but I need to delete the prefab from the right side as well to delete in from the list
no,. nothing yellow in this screenshot is a prefab
prefabs are assets that live in the project window
they do not live in a scene
as it is in beta state, I am used a rectangle with an Image, and saved it as a prefab
you might have saved it as a prefab
but the thing in the scene is not a prefab
it might be an instance of the prefab
yes, it is an instance from the saved prefab
but how can I find the third, or the first one to delete it?
Steve answered you already
just access it from the list
list[2] is the third element
(with list[0] being the first)
in the list, yes. But I created an instance for list[2] on the canvas. How can I find the instance ?
it's the same thing, they are references
You would have to have saved the reference somewhere
in a variable, or in another list, for example
or a Dictionary
in the List ?
or wherever
Instantiate returns the object it created
so you need to make sure you save the result of Instantiate somewhere if you mean to use it again later.
here is the code
What is itemsDisplayed
if I equip the 2nd item from ItemsDisplayed I need to delete the instance from the screen
what is inventory.Container storing
It looks lioke you're storing a reference to the instance in ItemsDisplayed
itemsdisplayed contains the inventory elements
you can and should just get it out of there
what does that mean
you have to understand we have no context whatsoever about what you're doing here
if I am using the destroy command and try to pass the itemsdisplayed[2], it not works
Beacuse ItemsDisplayed is not a list
it appears to be a dictionary
and the key is... I don't know. Whatever inventory.Container[i] is
so that is the same key you need to retrieve the object
but this is missing a lot of context for us, so it's hard to say exactly what anything is.
how come you are asking about Lists when you are actually using a Dictionary?
See how it's a dictionary
If you did ItemsDisplayed[x] = y; then if you want to get y back out, you do var y = ItemsDisplayed[x];
yes , for the UI it is a dictionary
or equally, if you did ItemsDisplayed.Add(x, y) then you get y back with ItemsDisplayed[x]
so destroy(ItemsDisplayed[x]) ?
replace x with the key you actually used
I will try
in your code it's the particular element of Inventory.Container that you added it with
thanks
Do you actually understand any of that code?
yes I understand. Bu I have no clue how to delete the instance from the canvas
that was the question
I will try destroy(ItemsDisplayed[x])
pasted in wrong channel again sorry -- keep forgetting about the input-system channel haha
what is x?
but you understand that the instance from the canvas is stored as the Value in the Dictionary, right?
Step 1. Get the reference
Step 2. Call Destroy on it
yeah, but somehow I cannot find the right reference, to destroy the right one
because you need the Key of the Dictionary that corresponds to the Value you want
but I read, the dictionary in not an ordered list
key X can be anywhere
the key is unique, right? just as in SQL?
which is why I asked if you understood your code which, apparently, you do not
yes the key is unique
it's weird to invoke SQL here
but sure you can think of the dictioanry key as a database key I guess
in SQL the key is part of the row you retrieve
here you are mapping one object to a completely different object
if I solved the destroy issue, I need to save the inventory in an SQL database
this is why I used a dictionary. Probably just to save the key
but thats the second part
I think one huge problem you have here is your inventory and everything is tightly coupled to the GameObject system
so that second part is really going to require you to completely rearchitect this whole thing
but we're digressing
when you use a Key you need to have the logic to recreate it otherwise you are just going to have to serial read the Dictionary, like you would a table from a database
i mean isn't the second element just the second thing in Inventory.Container here?
i.e. Inventory.Container[2]
if you want the third elemnt, use that as the key^
but you would definitely not be hardcoding any numbers here
as the player pick up the items from the ground, it will appear in the itemsDisplayed Dictionary
than I can equip it to the caracter
you are missing the whole point, do not confuse what is happening with the data
this is a code channel, probably best to ask in #archived-game-design
unlikely to find that here try !collab
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
โข Collaboration & Jobs
that is what the collab link is for
you would have to explain what you mean by "need help with scripts" for anyone to even say yes anyway
but if you are looking to collab with someone use the link
if you need technical help please find a relative channel to use
well you have yet to have said anything about what you want us to hep you with, also yes this is a unity server we talk about C# here as well
if you want people to collab with you and to actually help you with your project us the link, as that is what it is used for
ask your question here
or in a relative channel
such as #archived-game-design
literally ask your question
no, if its only 1 problem with your script like an error or something you do not get, ask it here, if you need volunteers (as you said here #archived-code-general message ) to help you please use the link as that is what it is for
we do not do collaboration posts here, this is what the discussion forum is for
what do you mean?
no, because you are not listening
oh okay their messages just got deleted, was that Danny?
I think OP self. Typical over entitlement, you should just do what I want
Hi, does anyone have some resources on mesh generation using a compute shader, I want to generate a mesh with a dynamic number of vertices (that isnt known at compile time) and i'm wondering how to do that, as all the tutorials i could find on it assume it operates on an existing mesh and deforms it, but doesn't generate new vertices.
catlike coding has a series on procedural meshes:
https://catlikecoding.com/unity/tutorials/procedural-meshes/
Hi, I am running a few small tasks at the same time
while(!done)
await Awaitable.EndOfFrameAsync();
essentially that block is waiting on lets say 3-6 objects at the same time. Is this bad for performance? Or would this not really affect it too much until theres hundreds of them runnning or even more?
You almost certainly want https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Awaitable.NextFrameAsync.html instead of EndOfFrameAsync
unless you're doing some special rendering thing
as for performance it's similar to running 3-6 updates
not a big deal
is there a way to allow polymorphism in a list exposed in the inspector?
if the contents of the list isn't MonoBehaviour-derived, the easiest way is ScriptableObjects. Second easiest way is something like odin serializer. Third easiest way is SerializeReference, assuming the list contents aren't UnityEngine.Objects of some sort
actually I'm not sure about the third thing for a list specifically, I've used it for single fields directly only
different question - is there a way to draw multiple lines for a single gameobject?
I tried using LineRenderer but it only seems to be able to draw one line at a time
this is just for in-editor stuff to help me debug things
although I'd hope to be able to draw lines in-game too
Hello!
Would anyone help me figure out why these errors are occuring?
They ALWAYS occur when I exit play mode, and some times they start during play mode. The same errors keep appearing thousands of times
have you actually set the value in the inspector?
you can use multiple LineRenderers.
Also if it's just for debug, try Debug.DrawLine
https://docs.unity3d.com/ScriptReference/Debug.DrawLine.html
cleared out my mess of code so I don't derail, got my issue sorted ๐
Did you check the code that throws the errors?
So it was actually because I had [SerializeField] on a non-serializable Object!
hy all i have an issue when making a HTTP Request in unity
i make this a standartd HTTP request call like this
Updated Code
https://hatebin.com/hsthbbbgcm
i dont know why, but the result is empty and yet i when tried on postman the result is not empty
hello everyone, I just started a new project and for some reason i get these errors even though i have not even scripted anything yet
have you tried to regenerate project? seems like you have a missing packages
old but its the one i used to enjoy working on a lot
I think it's time to update...
I already to have 2021.3, but the project im making i used to make it before with the same version 2019.1, but since i don't like to take risks even though update would be better i stick with the same version that i used to work on
Collab doesn't exist anymore. You'll have to remove the package.
a lot of things don't exist anymore
I have a target search with SphereCastAll using a "Homing" layer. The target is a separate object in the prefab. Question: why the hell does this method hit the enemy and not even its collider, but the parent object with Rigidbody (the collider is in the enemy parent on different object)? The enemy has a different layer than the one specified in the code
RaycastHit[] targetsInRange = Physics.SphereCastAll(origin, radius, dir, maxDistance,
param.GetParameter<LayerMask>(Homing_Mask), QueryTriggerInteraction.Collide);
This is what "Homing_Mask" parameter contains
fixed, thank you very much
are you running into this? https://docs.unity3d.com/6000.1/Documentation/Manual/compound-colliders-introduction.html
unity combines child colliders under a single rigidbody into a compound one
I replaced SphereCastAll with just SphereCast and now it hits the object with the collider, but it still shouldn't do that, because the collider layer is not "Homing", it's "Enemy"
nvm, it still hits the rigidbody
good, cause anything else wouldn't make any sense
what should I do
Here's what I'm imagining:
- you have a child with the layer you are querying
- you have a parent on a different layer
- when you do your physics query, it hits the child collider
3a) BUT as far as the physics engine is concerned, that collider is 'owned' by the parent on the different layer, so that's the entity that is returned by the collision query
does that make sense?
hard to say without knowing what you are trying to accomplish, but if you add a rigidbody to the child which you want to query directly, you should then be able to
hmm, yeah.. adding a Rigidbody helped
think of each rigidbody as 'owning' any child colliders under it -- they all point to it as the thing that is being collided with when any of them are touched
so if you want each collider to be its own fully independent physics object, it needs an RB
generally though, I would take advantage of that since it's often what you want
if something hits some npc or whatever, you don't want to get its child object with the collider on it, you want the wrapper for the whole npc
Unity Web Request
I had a bug(obviously) ๐
i tried various things but i cant find a proper way to toggle ragdoll physics on a character using a character controller with a animation controller
For ragdoll you typically would disable or destroy the CC and Animator and replace it with a ragdoll version of the character
Hi all, if I wished to implement this class as a template/generic type where it may either be int or float, how would I go about doing it? Should I simply make 2 variations or perhaps some sort of interface or generic? Thanks in advance
namespace Commons
{
public class PropertySet
{
public float min { get; private set; }
public float max { get; private set; }
public float cur { get; private set; }
public UnityAction<float> OnPassedUpperThreshold;
public UnityAction<float> OnPassedLowerThreshold;
public void RaiseEventPassedUpperThreshold(float n)
{
OnPassedUpperThreshold?.Invoke(n);
}
public void RaiseEventPassedLowerThreshold(float n)
{
OnPassedLowerThreshold?.Invoke(n);
}
public void Increment(float val)
{
var overflow = val + cur - max;
cur = Mathf.Clamp(val, min, max);
if (overflow > 0)
RaiseEventPassedUpperThreshold(overflow);
}
public void Decrement(float val)
{
var overflow = cur - val;
cur = Mathf.Clamp(val, min, max);
if (overflow < min)
{
var total = 0f;
if (overflow < 0)
{
total += Mathf.Abs(overflow);
total += min - 1;
}
else
total = overflow;
RaiseEventPassedLowerThreshold(total);
}
}
}
}
You cannot use operator(+, -, /, etc.) on generic type. Which make things pretty hard.
at a glance you'd need a later version of C# to do this as written and even then you'd have to implement your own versions of Clamp etc, so in current Unity you'd have to make wrapper types for float and int with the methods you need
Would an interface or factory of some sort be a viable solution to having types for this class?
Personally, I would just rewrite most of the function by hand or cast things to a common type.
You can use something like _makeref to have boxless convertion.
https://benbowen.blog/post/fun_with_makeref/
I see, thank you
Yes, but that would require you to create the function body which is usually want you want to prevent when doing generic type.
why doesn't Unity update the .NET version? It's incredibly old
they're working on it, but it's hard
THey are doing it though...
.net modernization is coming in unity 7. the switch to the CoreCLR from mono has been in progress for a few years now and we'll finally get our first taste of it sometime next year
https://discussions.unity.com/t/coreclr-and-net-modernization-unite-2024/1519272
yay! C#11 or 12!
i mean i don't know what i was expecting but awww
actually we'll get at least c# 13, they plan to release on whatever is the latest supported version at the time of release and 13 just released a month or so ago
and switching from mono is a HUGE leap forward
thank you this helps a lot
Hi there
I made an animation in which my player's model moves up. On the last frame it starts an event that calls a function which should move player's parent object to the model. However i don't know how to implement it.
I get the model's position with its spine bone, In hierarchy it looks like Player (parent ) -> player model -> armature -> spine
Yes, share it via !code and explain what's wrong
๐ 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.
!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.
Discord isn't letting me send it so can I send it as a screenshot
"You are over the message limit"
if you tried first link all you had to do is to paste your script there, than click save button and finally copy link of a site and send it here
I don't have discord pro
I can't get on links because of my family safety settings.
I'm legit in my late teens and my parents still won't let me get on sites without them rigourously searching through them beforehand.
So uh...
Guess i'm cooked.
can you ask your parents to let you open the link at least just for now?
Lemme check.
and they let you use discord?
I had to do quite the convincing....
now you should find a way to access any of those links to send us your code
it's just a text editor, so it should be fine
This is quite an usual issue, but I just can't find a way to fix it reliably. I've got a camera that I move in late update and for some reason, there's visual stuttering.
When I was first coding it it didn't happen, but after closing and reopening the project it started happening again. I have to say that what Im doing in late update is an origin shift, but it all happens at the same time by using an event
Could be an execution order issue. If you haven't defined an order then things might happen in a random order IIRC
Make sure your camera code runs after everything else
Lots of possible causes for stuttering though
cinemachine provides some options if you're not using it
specifically allowing you change rendering ordering on the fly
Thank you, it was indeed execution order
I forgot that previously I was running both at update, and luckly it fell in the right place, but when moving it to late update it was actually showing the visual stutter
I just had to make sure that after doing the origin shift, force a camera update
LateUpdate is usually the best place for camera movement
Googlefu failing. What's that secret key combo to change the editor camera pan speed?
It's something weird like holding right mouse button and scroll wheel up/down..?
yea
Oh, that was exactly it lol.. thought I tried that..
check "flythrough mode" in the doc here^
Or sorry - "Change the move speed of the camera"
As an aside, is there a way to make it "consistent"? It seems to be float based, so moving the scene around the origin is slow, but at larger manhattan distances it scrolls fast
generally focusing on some object at the desired scale sets it to something reasonable
with F or double clcik
hm.. I'll keep playing with it.. just navigating around the origin seems to be really fiddly and inconsistent
i set the pan speed to 1.36x and pan, then do something, then try to pan again and it's very slow (even though it's still at 1.36x)
not sure I understand what's going on under the hood
what would be the best enemy detection for an rts? overlap shere? trigger collider? global list of enemies and checking which one is in range? or something else?
Overlap sphere or manually going through a list should be fine. I wouldnt use triggers
if you have a huge world and lots of units you might be better off starting with overlapsphere since it'll do some kind of space partionining
yeah alots of units
i am using overlap shere rn, i just get lagspikes every time the script goes through the detected enemies to check which one is the closest (the units have turrets, and the enemy detection is on the parent, but every turret checks for the closest enemy.. because yk, the turrets are a little to sometimes far apart and have their own range)
danger hehe~
Maybe share the code then, but if you're doing this all at once on like 1000 units then yea theres gonna be lag
Also deep profiler can tell you more about where the lag is coming from
yeah i have to do that the whole time, ik that's why there is lag, but what would be a better way?
void EnemyDetection()
{
timer += Time.deltaTime;
if (timer >= 0.5f)
{
Transform nearestEnemy = null;
float nearestDistance = float.MaxValue;
foreach (Transform enemy in unit.EnemiesInRange)
{
float distance = Vector3.Distance(transform.position, enemy.position);
if (distance > DetectionRange || !IsEnemyInSight(enemy))
{
continue;
}
else
{
if (distance < nearestDistance)
{
nearestDistance = distance;
nearestEnemy = enemy;
}
}
}
if (nearestEnemy != null)
{
target = nearestEnemy;
}
timer = 0;
}
}
that's on every gun/turret on each unit
Have you tried overlapsphere first as simonp suggested?
Also it doesnt make sense why a turret or gun would have this script. Just the units carrying the items
One thing u could do is get the sqrMagnitude because you dont need the actual distance here
wdym overlapsphere
what's EnemiesInRange , is it just a list?
the result of overlapshere on the parent
may be worth looking at IsEnemyInSight too
no, the spaceships are huge, and if a turret on the other side of the ship would use the same detection, the range wouldn't work
thats why i cant use the same code for all
but if you can't get it any faster you could start looking at ways to run less stuff per frame, either don't update every turret every frame, or break up this logic so you can run it across multiple frames
it's every 0.5 seconds
thats a raycst to detect an obstacle
I see, definitely then use the deep profiler and see which part here is actually lagging. It could just be that you're trying to run too much logic and that's all
Like how many units have this script even
you could try turning it into a coroutine then, you could yield every x number of iterations so it's only doing so many raycasts per frame
all? i tested with 60 units, every unit has 4 turrets and i get lag until they found an enemy, which makes sense, i just need ways to optimize as much as possible
one easy one would be to use square distance instead of Vector3.Distance
"Using sqrMagnitude is a micro-optimisation, and in some use-cases literally no better than Vector3.Distance" is what i read
is it a micro optimization, but if you're calling it constantly it might matter. I donno how it would be no better though unless the compiler is smarter than I think
hmmm i will try
it can't hurt if you're doing it a lot, but yeah it's probably not the main problem
A square root call isnt the worlds quickest operation, and you'd be cutting down doing it a ton of times
deep profiler
yea yeah ok
if the problem is spikes, you might have better luck actively maintaining this list per turret instead of refreshing it every time
there are other tricks too depending on what your game is. are your enemies following set paths where you can know which enemy is furthest along the path, and therefore closest to the next turret? that kind of thing
uhhm the enemies move free so no (multiplayer too)
but yes, do some profiling rather than random stuff
ye ok
even if they move freely, presumably you must at some point determine how they will move, and maybe can reuse that information (like if each ship needs to path towards the closest tower anyway, you're already doing this work)
Maybe another small optimization: check if the distance is smaller than the current nearest distance before that if statement above. Basically theres no point in doing that IsEnemyInSight logic if it's not even closer than the current closest.
That is really hard to phrase lol I hope it makes sense, I'm on mobile or I'd type it out
i will write that down and try all your suggestions๐๐ป
Hi, I'm trying to execute a compute shader from a burst job, i'm not really sure what I'm doing but I'm wondering if this is even possible, all I found is some Reddit threads from 2019/2020 that claim that as of right now Unity does not support this. Any updates on this?
I'm not trying to asynchronously run compute shaders, just offloading the dispatch to a separate thread.
It is not supported by design. Jobs have very specific limitations due to what and how they are expected to do. Most of the normal unity API is not allowed, mainly due to the fact that a job would be running on a background thread and most unity API is not thread safe.
You should check the documentation on the jobs. It's all explained in details.
The dispatches themselves are pretty light though.
In the first place, I'm not sure dispatching a compute shader is thread safe API, so it might not work at all even if you were to run it from your own thread(not a job).
I have a scene that is missing a script, but it doesn't let me assign it to it...
Completely locked out.
what do you mean by that
I know exactly what script is missing, but it doesn't let me assign it
And no compiler errors, in case you wanna know.
what are you looking at the inspector of
The scene
Why would the scene have a script reference on it? That's not a thing
Well I guess it might be in the scene, but it's weird that it's not letting me open it at all.
what you have there is some kind of corrupted asset
the scene file is corrupted
A normal scene inspector just looks like this
what is the file extension of that file
๐ฟ nevermind
I confused TitleScreen with MainMenu (I didn't name them)
Well now I gotta figure out where the heck this Main Menu prefab is being used and fix whatever that error is.
Anyway, thanks guys
it's most likely a ScriptableObject not a prefab
Hey does anyone how or where I could get URP settings for a Quest game? I hardly have anything in my scene and its topping 50 fps
Troubleshooting performance issues starts with using the profiler and analyzing it's data.
hello guys, im new to the unity new input system, i did a lot of research and didnt found a specific method for tracking wich key is being pressed. I created a vector2 tab for movement and i need to track when the player is pressing A, W, S or D
The first hit on Google yielded me this
https://youtu.be/0z-6lxL_sS4
What's the specific issue that you're having?
๐จ Wishlist Revolocity on Steam! https://store.steampowered.com/app/2762050/Revolocity/ ๐จ Creating a similar input to Input.GetKey in Unity's new Input System can be a real pain, but if you're looking for an equivalent on GetKey in the new input system then this Unity tutorial will hopefully help!
๐ Get access to my tutorial project files over o...
How do i use that
Check the manual. It's explained in details.
got it thanks
this error appears sometimes when I end a play session or even sometimes when I launch the project
it doesn't show me a callstack or anything, so I am not sure how to track this down
the player is moving right but is move only when i press once, if keep holding the player dont keep moving
i set some bounderies that the player cannot cross
It does show the callstack though.
Seeing how a lot of it is in the editor namespace, I'd assume it's a random editor UI bug. Unless it breaks something, it's probably safe to ignore it.
Are you using any custom editors/inspectors that could be breaking?
I do have some custom editor scripts
Then make sure you handle null reference cases correctly. Seems to be a binding to a serialized object property that is being null.
okay, I will try to figure out where it might be coming from, thanks
hey I have this setup
on the Cubes I have a box collider and simple script:
public Vector3 targetRotation;
public Camera raycastCam;
public void OnMouseDown()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
if (Physics.Raycast(raycastCam.ScreenPointToRay(Input.mousePosition), out hit))
{
if (hit.collider.gameObject == gameObject)
{
Camera.main.transform.rotation = Quaternion.Euler(targetRotation);
}
}
}
}
any ideas why this is not detecting the mouse click?
Cubes have a layer Gizmo which Main Camera doesn't render. Only PerspectiveGizmoCam renders it
raycastCam is PerspectiveGizmoCam
You're combining two separate things. OnMouseDown only triggers when clicking on the object that has this script. You don't need to check for mouse click and do a raycast separately.
ah my bad, I thought it only triggers when mouse was hoovering over it
but yeah, it still doenst work
So either change the method to Update and put it on only one object, or just put
public void OnMouseDown()
{
Camera.main.transform.rotation = Quaternion.Euler(targetRotation);
}
on all objects you want this to apply
okay moving it to Update works
but now there is some issue with rotating
it doesnt change the rotation of that object at all
The only rotation that the script changes is the main camera's
ahoi, I have a piece of code on an object with a collider that executes in OnMouseDown(). Works flawlessly so far. Now my issue is that I want code executed in my movement update function when I press the mouse button but ONLY if the other object's OnMouseDown isn't triggered
so the object should always take priority but if it isnt hit with the mouse click some other code in a different script should execute globally
OnMouseDown is only for simple cases, for things like this it's probably better to do a raycast manually and then do the other thing if it doesn't hit the object
so in my case, do a raycast instead of the onmousedown, if it hits the object call a function on it that does the code previously in my onmousedown, if not do whatever else I wanted yeah?
Right, or if you want to get fancy, have it trigger events
I shall ponder my willingness to get fancy, thanks for the input
I have proven unable to get a hit with my raycast
nvm I was just being stupid
think it all works now, ty again for the help
hey, has someone followed that video ? https://www.youtube.com/watch?v=rSKMYc1CQHE ? only few seconds after begining he's using method DrawCircle() and I can't get it..
Let's try to convince a bunch of particles to behave (at least somewhat) like water.
Written in C# and HLSL, and running inside the Unity engine.
Source code:
https://github.com/SebLague/Fluid-Sim
If you'd like to support me in creating more videos like this, you can do so here:
https://www.patreon.com/SebastianLague
https://ko-fi.com/sebastia...
It's not really the kind of tutorial where you'd copy code directly from the video. Drawing the circle is an implementation detail that's not important to the main point he's trying to get across. You can use a sprite or 3d sphere for example if you want to follow along
But I'd suggest first just viewing the video through without doing anything yourself, and then going back to the start
thanks for u answer, tho I yet cloned his project in the past and just some weeks ago I implemented a delaunay's triangulation on points from a Binary Spatial Partition to make a Dungeon Generator ( with Kruskal to get the MST ). I would had liked that DrawCircle method to visualize the circumcircles and but had to use gizmos. watching the video I thought that method existed natively on unity, will experiment that simu with a sprite as u say ^^
I've seen that a decent few popular games make capsules "hover" on the ground. How is this actually done?
I would assume you're shooting a ray from the capsule but like.. what if the capsule intersects something and the ray fails?
It's not the springy sort of hover either its really snappy
Guys are any of these bounds considering object's rotation? (mesh bounds, renderer bounds, collider bounds)
And if not, how do i rotate them?
Shoot it from a distance where it wouldn't intersect something. Or use a layer mask to ignore the "something".
Maybe I'm just overthinking it tbh the scenario I gave was very uncommon. I'm just considering a floating capsule as an alternative to the sliding one right now since I'm having some horrible issues with keeping floor contact
Probably none of them.
What is the goal here? The bounds can do fast aabb precisely because they are not rotated. If you need more accurate collisions, use physics.
i want to raycast from each corner of the building so that i can align the building right on top of the terrain. (so that its not too low or too high)
i was using bounds to get the corner positions
You can rotate a point around another point/axis. I think it's a method in Vector3. Check the docs.
i got a prefab that I instance, this prefab has a lot of gameobjects with rigidbodies
when i do a trace i hit one of those rigidbodies, i would like to get the "top parent" of this prefab instance
is this possible ?
you could stick a component on the top object and do GetComponentInParent?
if the instantiated prefab is not parented you can use transform.root to get the top level parent
thanks
Hey, how can I detect if coroutine was stopped?
I.e. I do StopCoroutine(myCoroutine)
How can I detect that it was stopped inside that corutine?
you cannot, Coroutines pause on a yield statement, if the coroutine is stopped it just does not return from that statement
Makes sense, thanks
can someone make me a script for moving an object because i have been trying since yesterday
No, not on this channel or any other on this server
Iโm learning c# and already have experience with python and JavaScript. How much c# do I need to know to be efficient with unity
42%
Like after learning classes is there much else for me to know
Yes, a lot. It's a lifetime learning journey. But it's not a thing that you should be worrying about, just start doing and learn on the way
K thx
And in terms of a free ide, should I use rider or visual studio
Up to you, I prefer VS
I have been using VS since forever, but people also really like Rider
I would probably choose Rider if I start using it
VSCode though hasn't been supported for couple years so the community one might be of choise
Nah, Rider is like having a nagging mother looking over your shoulder
hello! I would likt to ask how to program some UI stuff I am trying to do, is this the right channel?
no, #๐ฒโui-ux
thanks!
are built-in components like Position Constraint or Audio Source monobehaviors? i.e., do they have Update() functions?
that's shown in the docs - but no most unity components aren't implemented as mono scripts and don't inherit from MonoBehaviour
if i want monobehaviour on a tree then i need to place object trees or can this be done on terraintrees ?
terrain trees are just regular prefabs..
will their code execute?
afaik it should like any other component.
if you have doubts 
Could I somehow make a dropdown list of all the classes that inherit from a base class? I'm trying to create a small list of every collider type to select from
Yes, with reflection
However, I would just hardcode them given that we are talking about collider type.
As simferoce mentioned, there are only like 5 collider types
probably simplest to just manually list them
MeshCollider, BoxCollider, SphereCollider, CapsuleCollider
I was just going to use an enum for them haha. Thought it might be nice to have an adaptive selection but I guess there really isn't much point
yeah only 4 even ๐
Switch case my beloved
It would take more effort to write code that enumerates them all than to just enumerate them
Guess I could also make a Component variable and just add that 
But then I'd have to check if it's a certain collider and that's far too much effort for a helper script I'll end up using twice
Hey, I'm trying to render sprites as hotbar item icons. The hotbar itself is made out of Canvas Images, which is a UI element. I added a Sprite Renderer component to an empty object under the hotbar slot object (the Canvas). Seems like everything else is rendering on top of the Sprite. Anyone know how i could fix this? The orange outline in the image is the Sprite
For UI you should use the Image component
not SpriteRenderer
SpriteRenderer is not for UI
oh that makes sense, thanks!
i just got it confused because the Item class saves the Sprite of the item (colleagues design) so I thought i would have to render it as a sprite
The Image component renders Sprites in the UI
yeah, just noticed
The SpriteRenderer component renders Sprites in the game world
If you're going for ultra-realism, strap a gopro to your head, look at a fixed point, run towards it, then replay the video and graph the offset of the point (both x and y) in a pair of animation curves, and voila! nauseating head motion. ๐
(I think head bob is best done in a very, very subtle way - so subtle that it probably doesn't matter what kind of curve you use, you just want a little bit of wobble)
can someone help me make a pause menu ive tried 29482942 different scripts none work when i press escape nothing happens the menu canvas doesnt show up and even if it does the buttons dont work
Is there any other solution to shared variables / methods apart from inheritance? I have some classes that share variables, other classes that share other variables, and all of them share other variables
I want to get rid of duplicate code but inheritance is not good for this situation
scriptable objects
i cant change their values and idk how that would fit my problem, you would have a lot of different scriptableobjects
for only 1 variable change
of course you can change their values
while running execution? I thought it was static
and if u change it in 1 object