#💻┃code-beginner
1 messages · Page 398 of 1
Hello everyone, I'm a French person studying C# currently on Unity. I have an assignment where I'm really struggling. Would someone be kind enough to come help me privately and explain? Thank you very much!
i mean even tho i have the brain funcionality of a dead rat i still made guns animations and 3d stuff byself with no help
so atleast im not a total moron
just post your question because DM is too much of a commitment
nah youre just creative
i worked so hard on this project 😩 i did so much and its only my 3rd
Yeah tutorial hell is real. And it sucks 👍
I generally feel forces are easier to get started with if it fits your design goal. Managing velocity directly definitely gives you more control and is somewhat more intuitive with regards to the actual math involved, but it debatably comes with the cost of having to... well, manage velocity directly.
how can i change the capsule collider settings? i need to change the layer overrides
@rich adder excuse the ping but i know you know about the kinematic charactercontroller
you ever heard of hollow knight? thats the type of movement im looking for, maybe they have some of there games code availabe but i highly doubt it
does it not working in the code?
Its been a while since I've used it I don't remember the collider being grayed out, havent touched that part
Definitely aware of it, but I've never played it. I'll go check out a video though
im assuming its this, but when i delete the readonly, only the field becomes ungreyed but the capsule remains grey
I didnt even know that you can make default components readonly like that capsule
is there some other custom editor script maybe for the capsul?
deleting and readding seems to make it writeable again
Is there any component above the capsulecollider? I wonder if some custom inspector leaves GUI.enabled = false by accident
It does seem like they're just directly manipulating velocity or controlling position as needed - there are no obvious gradual accelerations or friction or whatnot that I would associate with forces
It doesn't let you set the collider, iirc
I bet that's how it happens
so GetKeyDown works for pressing a key but what about holding a key? cant seem to find the right thing
GetKey
oh
ok so i now have movement but my x-axis movement completely stops my positive Y-axis movement so ill have to figure that out tommorow
Are you setting the Y value of the velocity to something?
So whichever one happens last is the one that decides what velocity is
They all overwrite the entire velocity
Yo @raw token after it working on the top left, I moved it to the top right bc thats where I want it but..
public static void DropItemIntoSlot(RectTransform slotTransform, RectTransform itemTransform, Vector2 cellSize)
{
if (selectedItem != null)
{
RectTransform grid = slotTransform.parent.GetComponent<RectTransform>();
Vector2 itemAnchoredPosition = itemTransform.anchoredPosition;
Vector2 gridMax = grid.rect.max; // Use max since top-right alignment
Vector2Int cellCoord = new Vector2Int(
Mathf.FloorToInt((gridMax.x - itemAnchoredPosition.x) / cellSize.x),
Mathf.FloorToInt((gridMax.y - itemAnchoredPosition.y) / cellSize.y)
);
Debug.Log(cellCoord);
Vector2 snappedPosition = new Vector2(
-cellCoord.x * cellSize.x - slotTransform.parent.GetComponent<GridLayoutGroup>().spacing.x * cellCoord.x,
-cellCoord.y * cellSize.y - slotTransform.parent.GetComponent<GridLayoutGroup>().spacing.y * cellCoord.y
);
selectedItem.GetComponent<RectTransform>().anchoredPosition = snappedPosition;
selectedItem.GetComponent<Image>().raycastTarget = true;
selectedItem = null;
}
}```
This system works great when I have the topLeft anchor and pivot for everything but now that I move it to the top right anchor and pivot for everything. The slot that should be 0,0 is 4,0. It's inverted.
How can I get it to 0,0?
😱 😁
That's sorta why I got so curious about a solution which would work independent of pivot and anchor positions last night - it seems like it would be something nice and reusable, without having to remember to adjust things if the anchors change... But I'll see if I can make sense of anything 👀
Am I better off just learning the subjects I need? or learning how to make a game with a tutorial on making a whole game?
Can anyone answer my question for what screen sizes for mobile there are, or how I should go on about sizing my games screen to fit mobile devices?
Thank you to anyone who responds!
Depends on what aspect you're trying to make fit
If it's an orthographic camera, you can scale the size property with some math to fit (as best it can, it's impossible to fit perfectly for every resolution).
For UI in screenspace, you can do that by setting a reference resolution on your canvas and correctly anchoring your UI elements.
alr thanks man
There are many different screen sizes on mobile. The mobile simulator package provides some predefined devices resolutions for you to test.
The full list would be very long, so you'll need to google that.
I think for that case you'd still want to use grid.rect.min rather than grid.rect.max, because you want your cell coordinate system to still start at the left, even if you have the grid anchored on the right. So it still makes sense to calculate the distance of the item from the left edge of the grid (e.g. itemAnchoredPosition.x - gridMin.x)
Where I get confused in all this is that I think grid.rect is relative to the grid's achoredPosition, and the grid's anchoredPosition is relative to the positions of the anchors... In my noggin it doesn't really add up that using grid.rect.min or grid.rect.max alone is enough to calculate itemAnchoredPosition's location (itself a position relative to it's own anchors) relative to the grid. Like, I feel like we should need to figure out the absolute/canvas coordinates of the grid (or if items are direct children of the grid, maybe just use the item's local position?) and the item to make sure everything works robustly in a manner which won't break when anything else changes...
...But I'm also not really sure what I'm talking about, here 👌. I'll be playing with this more, just out of curiosity
will try
Using grid.rect.min messes it up even more for some reason
Yeah alright - I guess that makes me feel a little less crazy... let's see...
lol
That's a bit complicated because it depends how your stats are setup. You'd have to pass the type of stat to affect . . .
Not sure exactly how your SO events are setup, but if they're similar to the method online, you should have a corresponding MonoBehaviour listener. Do you have parameters for your SO events?
I could just have built in methods that select the corresponding stat
wdym by 'method online'?
By parameters, you mean a CustomParameter class? No, I don't.
I was going with that idea but scratched it cause I found it unnecessary.
Main thing is not passing parameters, the main thing that's been holding me back is not being able to tell apart who the enemy player is.
Each card as a list of events, and each card is owned by a Player
But I can't find a way to make the event have acess to that player at runtime, because at the start of game a card can belong to any player.
Then have an owner field in the card that you assign the owning player to.🤷♂️
Although, I think i could make it work by passing Player as a parameter to an Event Constructor
Or handle the events on the player instead of the cards.
okay, bullet question
I have a code that is a child of a abstract code that is a child of a abstract code
once I do a override on a void that has already been overrided on the second abstract
the base. will refer to the last override or the base
How do I prevent the text from waterfalling over to the next line? Just cleanly going to the next line
private IEnumerator EffectTypewriter(string dialogText, Text uiText)
{
isTyping = true;
uiText.text = "";
foreach (char character in dialogText)
{
uiText.text += character;
yield return new WaitForSeconds(0.02f);
}
isTyping = false;
}
The implementation of the real type is used, so yes, the last override would be used.
Or are you referring to base.YourMethod()?
That would call the direct base class implementation.
thhis one
how do I refer to the last overrided?
Use TextMeshPro and the "maxVisibleCharacters" property instead of modifying the text
The one in this? Just MethodName.
There is nothing between this and base
Base is the class that this inherits from
and what if the class that is inheriting this method, has overrided this method from another class?
The implementation in the base(the direct base class that this class inherits from) would be used.
In this video I have shown how you can create a Type Writing effect in Unity using TextMesh Pro. TextMesh pro is the ultimate solution for texts in Unity. You can make different kinds of animation using TMPro's classes. I have shown one example here.
TextMesh Pro Documentation : https://docs.unity3d.com/Packages/com.unity.textmeshpro@1.3/api/...
It doesn't matter what's up the hierarchy above the base class.
okay, thanks
I'm trying to avoid TMP because it makes it difficult to work with Asian characters
There's not really a good way to do this without TextMeshPro.
But.. TMP has no problem with Asian characters
You just need a font and a font asset that's properly set up
I can try tinkering with it again, but I ran into some troubles with the character sets be limited IIRC
You have full control over the character sets in your font asset with TMP
Alright I can try again, fingers crossed
That's what using parameters are for . . .
A is abstract with a virtual method. B is abstract derived from A with an override method. C is derived from B with an override method. Calling base.YourMethod(); from the C override method will refer to the parent class B . . .
What can I do to make my crafting system eliminate changes whenever I quit the crafting station without having used my resources?
Use temp variables when using resources and update the actual resource(s) once the item was confirmed . . .
Or you can cache the original resource value at the start of crafting. If the crafting is canceled, then assign the cached value back to the resource . . .
If it's something of a drag and drop crafting grid then simply clear the grid while also returning the cleared items into the inventory
Its more of a click thing
I click on the object and an image pops up in the crafting slots
like when you press shift while clicking an object in minecraft
However, you shouldn't have to update the original resource; just check if the amount is less than or equal to the original resource value. Then, when they accept to craft the item, Update the resource . . .
Undstandable
Either way, if you're transferring your resources from one place to another then.. simply transfer them back.
I might get the original amount of resources and if the player cancells the crafting, use that information
There are multiple ways, as long as it works, it's good
how can I make sure that the craft was cancelled?
By calling a method which cancels it?
yes, but I have a problem there
What kind of problem
My inventory is based on item slots which each have the quantity of each item that the player has
Yes, and?
so whenever I use the crafting system if I "place" an object in the crafting station, the quantity is substracted
Yes, so?
but what if then I decide I want to quit crafting and want my objects back again?
Since you know how to transfer an item from the inventory to the crafting station, I believe you would also know how to transfer it the other way around
Simply iterate through each crafting slot and send the item back to inventory
yeah, but how?
Simply reference your player inventory from the crafting station and transfer all the items back
The same way you do it from inventory to crafting
How are you transferring the items from the inventory to the crafting station right now?
@brittle crown I'm at a loss... everything I'm coming up with seems suspiciously convoluted. There has to be a better way
just clicking on them and every time I click on top of one of the objects in the inventory, the crafting slot shows the sprite of the object
I know that much, but show the code.
How do you reference the item, how do you subtract from the inventory and how do you add to the crafting station
_itemsInCraft is an array of Items(ScriptableObjects)
_itemImages is an array of Images that show the sprite
I havent done it yet because I dont know what to do honestly
I know man.
The same way you transferred the item from the inventory to the crafting system . . .
dont get it with that information
Just a question, but would taking out an item from the crafting station shift all the other items there to the left or leave a hole?
leave a hole
Ok, so either way, you have referenced the Crafting Manager instance
A fast solution would be to just do the same for the Inventory
Or just add a function to the Crafting Manager which returns all the items
what exactly?
Look at the line where you declare the CraftingManager variable, in the method AddItemToCraft.
Now imagine yourself making a method named ReturnItemsToInventory, but within the CraftingManager.
Same logic
could you write a brief example?
Hmm what is causing my dialog system to toggle between 0 and the current state of the dialogInt? Resulting in me being able to re-skip to the beginning of the first element of the dialog
Does it have something to do with the coroutine?
void ReturnItemsToInventory()
{
PlayerInventory inv = PlayerInventory.Instance;
foreach(ItemScriptableObject item in _itemsInCraft)
{
if (item == null) continue;
inv.AddItem(item);
}
}
line 85 seems you set it right back to 0 and
canvasDialog.SetActive(true);
at the start of that else statement
Okay, and what about the quantity?
Is there one item per crafting slot?
yes
Then what about it
Just add the item to inventory
and increase the value
First of all do not ping people not already involved in the issue
Second of all, the first thing you can try is to pause the game as soon as you start, click on the slime in the hierarchy and look at the inspector to see what's going on
Maybe the sprite is missing or turning invisible? Maybe something is wrong withe the layers? Move the background, see if he's below it, etc
The Z position maybe
Not sure tho, it's been a while since I had camera issues
how can I reset the slot I clicked in?
Are you using two accounts or something? 🤔
That worked!
is it on the scene
because of "box collider" is not Collider 2D
Check your code. It should die or call a method to be destroyed . . .
Can you show me your code?
Enemy script
when this value is -8? on playing game or you wrote?
Then first , replace "animator.settriger function" to RemoveEnemy()
If doing well
I will let you
no
delete ("Defeated") also
You never call RemoveEnemy . . .
You never call the method RemoveEnemy. That's why the GameObject does not get destroyed . . .
I think animator.Settrigger("Defeated") will call RemoveEnemy()
Then I would follow some basic tutorial instead of jumping in over your head. You just need to call the method that destroys the GameObject . . .
But for test it, first replace animator.Settrigger("Defeated") to RemoveEnemy()
@last forge , first replace animator.Settrigger("Defeated") to RemoveEnemy()
Did you edit animator?
If you didn't, don't use animator.Settrigger("Defeated")
result wil be same
animator.Settrigger("Defeated") is only can work when you edit animator
Then what did the tutorial do? You have a reference to against . . .
There's a layer called "Ignore Raycast" in Unity's default layers. Is there a way to set up other custom layers to be ignored by raycasts as well? (without having to add a layermask every time I use Physics.Raycast)
So in the tutorial it doesn't work as well?
its more like, why should we hunt down the "smth" you have missed.. if the tutorial is functioning the way it should, you need to just rewind it and compare everything that was done... we'd pretty much have to look into the tutorial ourselves to really know..
it wasn't him getting pissed off either.. he just asked a question bout the tutorial.. you made it more than it was.
unless you got obvious errors in the console we can see.. you should do the bulk of the work and find what you missed when others can be spending their time being a bit more productive than that..
no hate just facts
So I've seen this but it seems to just be a constant I can reference to select the default Ignore Raycast Layer(?)
Does not seem like I can add more layers onto it or set it.
you could use a custom layermask
w/ the ignore layer selected
wait. let me backup.. i dont know what ur doing
That's what I was trying to avoid, though. I was wondering if it was possible to add more layers that function similarily to the defualt layer 2 "Ignore Raycast" layer.
u could probably do that in the code.. search additional layers after the ignore.. or u could construct an array of those layers and compare that
Would it be smart to have a separate controller for projectiles, explosions, cannon movement? Or should I combine them all into one controller?
from what ive learned. if it can be done in the editor it can be done in the code
depends on how big of a scale ur going.. u could put them all into one.. but it'd be more scaleable if u had a system to keep them seperate
in ur case (1) controller that could fire many different projectiles (the projectiles could spawn the explosions)
If the tutorial version works and yours does not, that means you missed a step, no? I would go back over the tutorial and double check your work . . .
can someone help me change the target sdk for android from 34 to 32
not coding question #📱┃mobile
sry
anyway it should be in the project settings afaik
Exactly, I agree. Asking for help is fine, but we found out you were following a tutorial halfway through helping you. It only makes sense to recheck the tutorial, especially if you suggest missing a step
The answer lies within the video. If you covered the tutorial again and are still experiencing the problem, I suggest linking the tutorial so we can check along with you . . .
is this the right way to find this component?
var textMeshProComponent = GameObject.Find("ProgressText").GetComponent<TMPro.TextMeshPro>();```
it's coming back null
Maybe you should reference this as a field from the inspector?
if the script is on the text element u could use GetComponent<>(), or that ^
wouldnt recommend Find unless its absolutely necessary
the script is not on the text element
then do what Dalphat mentioned
just out of curiosity, is the component type wrong?
yes
you need TMP_Text (this one is shorter and works for mesh one as well its base class)
or TextMeshProUGUI
Create a public text mesh pro field (or text mesh pro u g ui field) and drag that object into the inspector field for the script.
Use TMP_Text (the base type) if you're unsure. var is implicit so I'm guessing you're questioning the component type gotten from the Get Component call which you can read about here https://stackoverflow.com/a/74794832
Other than that, Find can return null and ruin your day so best just set up the references from the inspector when possible.

ah my bad. maybe you can just create an extension method which does this for you then.
though i do find it odd you need to have another layer which also ignores raycasts
Yeah. I just didn't want to have to redo any code I already wrote if possible
😅
I probably don't. But I was thinking of ways to solve a certain issue I have.
how can i change the game's camera?
Modify your Camera component
Do I need to change the tag from whatever, to MainCamera for it to be displayed in-game? If so how can I do this via script?
A camera tagged MainCamera is the one that's referenced by Camera.main. That's all
I see. However, I'm aiming to change the camera that you use to see out of like when you're playing your game. I'm guessing that's not the same thing then?
If you want to switch between different "shots", that's what Cinemachine is designed to do
there's no like built in way to just switch cameras? I have multiple in my project that belong to different players. for whatever reason you can see out of the other player's camera, I thought disabling every one except for the local would do the trick but I'm not sure how. What's the point of having multiple cameras in that case?
if you're referring to multiplayer then you definitely shouldnt be doing multiplayer. And yes you would usually disable (or only enable) the local players camera. You're probably just not doing it right
I hate the disable enable architecture for multiplayer. We prefer to keep two different prefabs for a local player and a “ghost” or as we call it the puppet.
got it thank you! I've got some experience with networking. this is mostly just a practice project so I can be familliar with unity. I figured it'd be good to start somewhere although, I'm using photon so hopefully it'll make things a ton simpler.
my only issue now seems to be that since my player is a prefab, I can't really access the child camera inside of it. I can only access the player gameobject. maybe im misunderstanding this.
ooh, I will definitely give that a shot thank you
Im confused why would you not be able to access the camera ?
Also are you trying to create a system where you can view other players pov’s sorta like counter strike when your dead ?
my prefab shows up like this whilst it's not in-game. I can reference the prefab, but I can't reference any of its children. If i double click it, I can modify and view the children but I still can't reference since it takes me out of the explorer.
I'll probably do that in the future, yes. although when you join in-game right now you're basically stuck viewing the other player's camera but you can still control your own. I figured all I had to do was disable the other cameras.
There is a handy GetComponentInChildren
That is all you have to do
I'm thinking of extending Transform, is there a reason it's not a good idea? 
can you reference a specific one? to my understanding you can reference the type of object you're looking for within a child with GetComponent, but you can't really specify
Do you have more than one camera in the player prefab ?
Do what you wish my man
Nah, this should work just fine. although I'll probably add some later for functionality with an idea I'm concepting. Just for future reference incase this messes something up when I do
if u end up with multiples u can use a method to get all types and then loop thru them & use comparisons to find the 1 u want.. maybe w/ tags or layers
https://docs.unity3d.com/ScriptReference/Camera-main.html can be helpful too if u just using the camera tagged MainCamera
uh oh, okay is there a way to get the component in grandchildren?? i have my camera inside of another object of my player's child.
GetComponentInChildren is recursive it will search all children untill it finds a suitable component
The level of nesting does not matter
i swear, im so dumb. my script was working fine I just forgot my ! to signify not, and had my else statement swapped by accident
!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.
https://gdl.space/ikumaqolek.cs can any one tell me wht is this happening?
What is happening? Purple shader? Unsupported shader then. Or what is happening?
the unsupported shader area
do you ever assign a material to it?
i am trying to do a raycast but it is being weird
at the moment it is only a mesh and a mesh renderer
So please take your time and write down, what you are expecting and whats not working.
i was hoping that the ray cast could detect enemies in range but it is acting weird when ever the enimes are in range it dose this
I am wondering, why you are decreasing your angle instead of increasing
So your circular behaviour is intended in 180 degrees, I get that. And it looks like its working so far. But you are just setting the vertex to be at that point where you hit the enemy, which can result in your mesh being deformed as you see there. Open any 3d modelling software and just drag one corner of a rectangle across the opposite side and see what happens, thats what you are doing right here. So the code seems to work
Thats why I was asking, what are you trying to achieve here? looks like you are trying to create like a shadowcaster in 2D?
I suggest you to look at your generated mesh in wireframe mode, which will tell you more about your topology
Where can I find accurate documentation describing how to attach a value changed handler to a UnityEngine.UIElements.Slider?
im very bad at coding so can someone help me make it so when i touch a block in game the timer stops
but like it doesnt reset it, it just stops where its at
add a bool, branch the logic when bool == false
huh
i dont understand code very well, im still learning (thats why i came to code BEGINNER)
void update(){
if(!timerStopped){
//do timer logic
}
}
void whenYouTouchABlock(){
timerStopped = true;
}
like this
you can't have two Update()
oh
You will want to do some C# tutorials
like this then right
Put the if-statement at the start of the method, check if the timer stopped (not the opposite), and just stop the method if that it the case.
You can stop a method with return;
Then, have another method that is called when you touch a block, and have it call timerStopped = true;
You may want to put lines 28 and 29 inside the if
void Update(){
if(timerStopped){
return;
}
// Do your draw logic here.
}
public void StopTimer(){
timerStopped = true;
}
This is called a "guard" clause. Check if the method should continue at the start, or stop the method if that is the case
Your block then calls StopTimer in whatever way it should
That will work, assuming that you have no other logic in Update that needs to run when timerStopped == true;
They don't
Otherwise I would advice you make a new method for the draw logic and do the same thing
what
In general you should not apply logic in Update, only call methods from that have have individual taks
i wouldnt know
i have 0 experience in coding
i dont even know what yall are even talking about
If you have 0 experience in coding I suggest you stick to basic C# before you start using Unity
Unity is a whole other thing and it will be very confusing to learn two separate things
Unity does a lot different
i didnt make it i watched a tutorial
I still suggest you start with basic C# and check out tutorials for that
Right now you try to learn both C# and Unity, and this is very confusing
right now i wanna get the game out, not learn c#
lol
I'm afraid C# is going to be required when you want to do anything meaningful
But suit yourself
Generally knowledge on the basics of C# are expected in this channel because we don't help with these things
You can't really cut corners in your game with this, you might as well prepare yourself properly and learn properly
well this type of game im making, everyone has already made the scripts so i dont need to code i just use everyone elses scripts
And now here you are with no idea how to apply a simple change
We don't really spoonfeed here, please get used to C# basics and save yourself the trouble of having to ask every single simple feature
BC I DONT CODE
I ALREADY SAID THAT
I CANT CODE
then you can't make a game
So why don't you ask one of your team members to do it then?
team members?
I don't really understand why somebody who doesn't have any idea on how to code, works on code
you wanna see my game
Are you a single person trying to make a game?
this is my game, you think a have a team
And everything in here is copy pasted scripts from other people while you have no knowledge on how these work?
sorta
i sorta know how everything works
but not well
You know it in terms of what the script should achieve in the game, you just don't know anything that actually happends code-wise?
i sorta do
i mean ive done very little 2d coding (while following tutorials) but not 3d
are u gonna help me or not
This has absolutely nothing to do with 2d or 3d coding
This is your refusal to learn basic programming and I really doubt you have even the slightest idea on what anything does in those scripts
And no, I'm not helping. We don't spoonfeed in this channel. I'm amazed you even made it this far when you just copy paste scripts
Do you know where can I find accurate documentation describing how to attach a value changed handler to a UnityEngine.UIElements.Slider?
literaly every game like this is just copy pasted scripts so whats wrong with me doing it
lol
i just wanted help
https://docs.unity3d.com/6000.0/Documentation/Manual/UIE-Change-Events.html
Not slider specific, but UI toolkit specific.
slider.RegisterValueChangedCallback(v =>
{
var oldValue = v.previousValue;
var newValue = v.newValue;
});
That does not work, also it is from stackoverflow and not official documentation, if I remember correctly. Oh, nvm you posted the doc url
Why not?
I gave you help initially and you had no idea what I was talking about 🤷♂️ #💻┃code-beginner message
I dunno why it doesn't work. I didn't make UI Toolkit
Just read the examples in the doc then, they should work just fine.
Which examples have you seen that actually work? I have not seen any yet.
In my UIToolkit deep dive to see if its better now compared to years ago, all of them worked just fine.
They also have an asset project with examples of almost anything UIToolkit related.
Oh?
slider.RegisterCallback<ChangeEvent<float>>((e) =>{Debug.Log("callback")});
also does not work
What does it say then?
I'll check out that project and hopefully find something
does not work is useless for a programmer, give some context like the stacktrace or the error description at least.
I did not say there is an error.
So it does work, but it doesn't write the log?
The expected behaviour is that it would write to the log, but it does not.
audioSlider.sliderVisualElement.RegisterCallback<ChangeEvent<float>>((evt) => {} works for sure.
And where do you register that callback then? Show your full code.
Oh, I think I have a reference to the UIElement.Slider and it needs to be the visualElement
My guess you passing not corect visual element.
my code have scriptable objects and etc. So it will long to copy paste. But the callback was decribed correctly, Most likely selection of visual element was incorrect.
audioSlider.sliderVisualElement = parentElement.Q<Slider>("slider");
if (musicVolumeSlider == null) {
throw new Exception("slider should not be null");
}
musicVolumeSlider.RegisterCallback<ChangeEvent<float>>((e) =>
{
Debug.Log("musicVolumeSlider.RegisterValueChangedCallback");
});
sliderMusicVolume is not sliderI think. It is parent obect, which have slider inside of it. at least it was two years ago
"sliderMusicVolume > VisualElement"?
how does it look like on your end. does it have visual element icon or slider icon. depends on that.
looks like I need to get the child VisualElement, perhaps
maybe try Q<Slider> instead (Slider)<..>.Query("sliderMusicVolume");
it should be the same tho
Yeah, I would expect the generic just does a cast
Are you saying I should target the Slider or one of the things inside it?
that's the whole thing expanded
you should get the Slider it self for the change trigger
Yeah, I would expect so
test fail
so, it definitely is not null, but the event does not fire
I believe the documenatation is not accurate.
just in case. you low and high values are set to be 0 and 1 right? not the same>?
high value is 100
I think this component comes with UI Toolkit
or maybe I made it and forgot
have you checked if musicVolumeSlider is not null, just to learn if it finds correct element
no, I see Slider in the standard controls
Where do you call this?
Start
Yeah seems valid to me.
Can you show a console screenshot? Your not hiding your messages right?
So that 'caller' is in the same start as your callback?
the red arrow points at the start in question
Ok, we definitely have a Slider
I think the handler is applied, but not called when the slider is manipulated.
Is there a way to print a list of callbacks?
Do I also have to add a manipulator like with buttons?
Nope, I did a stupid.
perhaps more than one
Ran this and got nothing, so maybe a timing issue?
Debug.Log("element " + x.name);
x.RegisterCallback<ChangeEvent<float>>((e) =>
{
Debug.Log("testing callback " + e);
});
});```
I honestly have no clue.
Registering a callback should be extremely easy, it's 1 of the most basic functions of UI.
The examples show how they work, and the tutorials were easy to follow.
Perhaps start over with a clean scene/project?
Could probably convert the query to a list and check the count just for debugging purposes
that is basically what the foreach does
Although getting no log simply implies an empty list already
Maybe the line of code never executes?
Gonna restart Unity. Too many times has UI Toolkit desynched and caused insanity.
UI Builder is garbage
I think I'm gonna start doing all my UI work in Notepad
FYI, the cause of all that faff was UI Builder lying about the contents of the template. It desynchs from the xml and edits no longer save to the file. This causes a lot of confusion.
Well, thanks duckies.
You're all very smart and handsome.
fyi, I use UIToolkit a lot but never UIBuilder, I do it all through code as it's much more stable across Unity versions
Command line interface is the best ui there is. No need for fancy panels.
Yeah, we wouldn't want someone to be able to do things without a reference sheet
is this the correct way to get a random value in a range of 3?
no, that will produce 0 or 1
so i have to make it 0,3?
read the docs
I would do some testing with that and see what the results are anyway. I don't trust documentation.
hmm, your life as a developer must be hell then
I definitely do a lot of testing
I believe the phrase is 'Trust but verify'
If you cant trust the documentation on something simple like a random number, that's a reading comprehension issue
and that was especially useful when ES6 released, and all the list comprehension features they added tested orders of magnitude worse than a simple for loop
this is my script for a monster to appear is there anyway i can change this to when i walk through a trigger a sound effect plays? im new to coding and i dont really know what im doing
Use the collider to play an AudioClip with an AudioSource
what would i write
You would write the C# that would use the collider to play an AudioClip with an AudioSource
Always refer to the docs
https://docs.unity3d.com/ScriptReference/AudioSource.Play.html
how do i get the audio to play when i walk through the collider
Please configure your !ide before receiving help
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
did you look at the docs Ilinked?
i did but i dont understand it
do i just copy it?
no, you do not. You read it again and again until you do understand it, it's pretty simple
The docs have an example you can take reference to. Create an audio source, get the component in the script and play a sound on it
And please check my previous message and configure your editor. Currently it's going to get very annoying and cumbersome to work on your game with the way it is
i use visual studio code
See bot message for "VS Code"
how do i configure it
Follow the link in the bot message and follow the steps
If there's a specific step you have issues with, feel free to ask
is this correct?
No, there are multiple things wrong here
Configure your IDE first please
It would correctly highlight more parts of the code if you did
Perhaps you missed a step
real developers use Notepad
cool
lol
dumb question but is there any shorthand for getting the screenwidth and screenheight as a Vector2 or Vector3?
Don't think so, closest thing is probably currentResolution: https://docs.unity3d.com/ScriptReference/Screen-currentResolution.html
But you can still make it a 1 liner anyhow for vector2 or 3, not sure why you ask this tbh.
🫡
In my current instance I have a UI object that should move towards the top right of the screen at all times, and each object would inevitably have a static Vector3 screenResolution = new Vector3(Screen.width, Screen.height)
I haven't tested this code yet but I wasn't sure if Screen.width and Screen.height get defined before runtime
why would you use a Vector3 for a 2 dimensional space?
its really just to store the object's destination position, vector2 works too
is there a better way for doing this? i feel like checking the velocity on every internal physics update frame might be a bit inefficent.
trying to play physics object impact sounds btw.
Why?
Is this for saving data?
no
fishnet needs a custom serializer
because it doesnt know what to do with it
!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.
nevermind
i decided im just gonna pass in the models
instead of the actual class
https://gdl.space/akukehilon.cs health script
https://gdl.space/ujopifawov.cs detection code
https://gdl.space/seregiwuqi.cs bulletcode
now i can fire bullets but the bullets are not doing any damage idk why it is not working anyone who can tell me what the problem might be here?
how do I make it non local
local means it is encapsulated within a method
private Sprite firstWeapon; - doesn't need to be public.
Consider changing your code to use CompareTag rather than checking a string directly like you do currently
thanks but what difference does it make
CompareTag is faster and eats less memory
check the pinned messages. it's one of the best practices . . .
Also generally you should just use it even though the reason doesn't apply. It exists to fix a specific issue and there's not much reason to not use it
more info is needed. do you have any code?
yeah
It had something assigned previously, the type got changed, and now what's assigned is the wrong type
Re-assign the thing you want in there
Delete that code block and 👇
!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.
!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.
ty
did you change the type of the variable?
📃 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.
omg im sorry
lol
!code is the bot command, you're supposed to read the msg it spits out at us :p
📃 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.
use one fo the sites . . .
What did you try to assign?
this one
if that is a GameObject, you cannot assign GameObjects to Prefabs
there is other way?
:((
you have to assign it after the prefab is instantiated in the scene . . .
yes, use a singleton or dependency injection at the point of instantiation
You can also try to find all Gameobjects with the tag waypoint in your Scene, so you dont have to assign them by yourself.
waypoints = GameObject.FindGameObjectsWithTag("waypoint");
very poor advice
sorry 😦
Did you actually read the API shown or just copy/paste it?
what should i replace public Transform[] waypoints; to ?
you should read the API
can u help me :v
'FindGameObjectsWithTag' - Objects is plural. So you need something similar but singular
ok i fixed thx everyone
Thanks everyone so much :D
this is my first time so im very stupid
is it too if the update loop in my game almost takes around 0.5ms?
most of it seems to be from the unity input system, which at one time even spiked up to 5.66ms, but thats very rare, it usually stays at around 1ms, but thats out of my control.
0.5ms is pretty darn reasonable
that would let your game run at 2000 FPS if you had no other things taking up frametime
you need to test/profile the game on your target hardware
if you meet your framerate targets with a reasonable buffer, then you're good
What frame rate are you targeting?
is 120 good for a qhd monitor on the target hardware, with max settings?
im not targetting anything lol. just whatever is good for a single player fps game
that's up to you.
We can't tell you what to be satisfied with
60 fps is the gold standard. If you can get that, it's good enough.
Which means you have a frame budget of 16.6 ms
so i should be good then, now i need to optimize my load times. you have no idea how much shit i have in Awake() and Start()
Consistent framerate is also a good thing to look for
my game currently runs some expensive AI calculations every 0.25 seconds, which causes a noticeable spike in the frame times
(in the profiler, at least)
they don't feel too bad in game yet
its okay if my frame rate is hard capped like this right?
also surely there's gotta be a better way to test on a low end device than buying one
You could try a VM, tho GPU partitioning is a pain last i heard
Could also ask people with bad specs to test for you
my laptop gpu probably wont work for that 
im just thinking if my game needs too much compute especially since its for mobile
now that you mention it, i hopped into a scene that had lots of ai agents, and i saw that my AI fsm and targetting system cause inconsistence framerates.
how can i fix that?
my targeting system dosnt run every frame but the fsm does.
im using the unity hsfm package for that
Not familiar with that one.
i'm thinking of jobifying some of my AI code (it just takes in a bunch of data, crunches it for a bit, and spits out an answer)
it does have to ask for the positions of a few transforms, though, which won't work
does the job system just split tasks into different threads?
It helps you run code on worker threads, yes
how can i make my code complete itself for example if i write "GameOb" it corrects it to "GameObject" i see it in youtube videos but i dont know how they do it i use vs code
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
i already did that before
ok
This may also be helpful: https://unity.huh.how/ide-configuration/visual-studio-code
thanks
i did it do i have to restart my pc or visual studio?
ok
I'm trying to check for a component in a children that is instantiated from another script before this Start is called (at least that's what i see from script execution order and a debug log test when the children is instantiated, which appeared before another debug log from the start function of this script)
basically the problem is that it doesn't get the component in the children, but if i try to get the component in Update, it works. So i think it has to do with the order of things, but I don't understand where to even start to debug this and fix it
To start debugging, use Debug.Log
you can print when the instantiate happens and when this Start method is called
so you can see what order that happens in
It's weird because if I move that one line of code to this method, it works
why is that weird
Again - debug your code
because CheckForFuel is also run on Start
that doesn't make sense
something is missing here
logs will help
or the debugger
Are you getting a null reference?
What do you need me to debug?
I already ran a debug log test for when the child is instantiated and this start method is called, and it showed that the start method is ran after, so in the correct order
no
Then what is the symptom of the problem
what makes you think it's not being found
Missing means it was destroyed
Perhaps the code inside CheckForFuel is destroying it
that would explain why swapping the location of the code causes it to be found
so i created a list, just to see what was happening, and indeed, it is creating 2 and deleting the first (which has to do w/ smth else in my scripts)
Anyway there's definitely more to the puzzle here than what you shared
appreciate the help
This whole scheme of Instantiating in one place then Finding/Getting later in an unrelated Start function seems a bit fragile. I think you'd be better served directly handling the reference you get back from Instantiate and sharing that/storing that as needed.
wdym by "if 7 contains 4"
wdym like ? (a & b) == b;
Hello
I set up vs code for unity and it works fine, the game objects do as the code I wrote says
But I get this error once in a while and it really annoys me
I've tried reading about it and even ask ai but I just can't figure out what this is while everything works fine
Projects failed to load because the .NET Framework build tools could not be found. Try installing Visual Studio or the Visual Studio Build Tools package, or check the logs for details.
vs code for unity and it works fine
are you certain of this?
also which app gives you error
isn't that what AND is for?
As certain as I can recored a vid about it
Vs code itself
you mean the 3rd bit:
100
^
this one
without >>
(this example is checking in a byte but it works the same in int or long)
i wont understand these at all
You will need to use bitwise operators to check bits
try to learn
Vs code is a weird thing, I've installed both .Net 9 and 8 but it still insisted to download it itself but it didn't just more dots appeared on screen
<< is simple.
1 is 00000001
1 << 3 moves all the bits over 3 times:
so 00001000
cant i read same way
My Microsoft Virtual Studio 2022 just closes whenever clicking on an error to try to see what is going on in the scripts or code :( Does anyone else have this issue?
no idea what that means
yes you could do this:
int mask = 4;
int masked = myNumber & mask;
bool contains4 = masked != 0;
Biut this is the same as:
int mask = 1 << 2;
int masked = myNumber & mask;
bool contains4 = masked != 0;
yes i know just | is much easier
also the same as:
int mask = 0b100;
int masked = myNumber & mask;
bool contains4 = masked != 0;```
But thank God after reinstall it ( almost got my whole os damaged ) it became logical again
And any idea on how I can fix that error i talked about before?
there is a simpler way
[Flags}
enum MyInt {
isFour = 1 << 3
}
...
int i = 7;
if (((MyInt)i).HasFlag(isFour)) ...
which error? who's giving you error ?
The :
Projects failed to load because the .NET Framework build tools could not be found. Try installing Visual Studio or the Visual Studio Build Tools package, or check the logs for details.
And vs code itself, in " notifications "
did you install the correct VSCode extension for unity
have you removed the VSCode Editor package from Unity package manager
try also regen project files
I didn't even install it, before I reinstalled it I had the extension downloaded from vs code itself, but it said it was old ( unity extension by Microsoft)
I do have it
Uhmm I'm afraid I don't know what "regen" mean, does that mean regeneration?
who said it was old? thats the one you need though
you need to remove it
yes it means Regenerate project files, its a big button where External Tools is in unity
Are you sure?
positive
the only package you should have in Unity package manager is** Visual Studio Editor**
thats the "new way" meant to be used for VSCode 
Is this why my Visual Studio crashes? I click console errors in unity, it opens all the way up, and then it closes
Visual Studio? It shouldnt crash no. You're talking about the
one ?
Yes
Microsoft Visual Studio 2022
So Uninstall VS and then reinstall? Okay thanks
that be the first I'd try
Thank God I didn't install vs then
If I had that error my dad would have killed me for using that amount of Internet and failing to get something out of it
VS is generally the superior editor actually.
why not
don't think Visual Studio uses the internet while in use (maybe once for activating license)
No, I'm talking about the download process
You said he has to delete vs completely
ohhh right.
The last time I saw the installation page it was like 17 gb
17 GB!
VS install depends on what components you install with it
The file you download from the site is an installer, it's tiny
yeah VS with bunch of workloads and I'm at almost 70+ GB
iirc MAUI alone was like 20GB
Mine's 4.5 GB
wait, with all workloads? 😮
with whatever is reqiured for Unity to run, nothing more
ohh ok
so.. C++ and the game one?
was about to say lol some of the workloads are taking way too much space for mytaste 😦
Well I think I downloaded 5he wrong version then
Idk
what do workloads do?
add support for various things
They are like extensions in vs code.
They add functionality
Edit: support is a better word, like carwash said
ah okay i was mistaken MAUI is only 9GB its my UWP thats like 12
so together they made 20gb
aw man I got pretty much all those checked off except for Python and JS 🤢
🥲
and as usual...unity takes down Links without migrations
there we go
thanks the enginneers at webarchive
I should have never installed unity extension
who wants to create content? 🙌🙌🙌🙌🙌
who wants to create redirects? 💤
that is all because i want to make a countdown 🥲
The whole thing started again
lmao like what the hell is going on internally fr
no learning something to do it correctly you only need to learn once
start by using proper naming conventions
isn't a requirement but it will help your own code later on..
Use pascal case nouns for class names
and share code properly
then this is the count down
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.UI;
public class countdown : MonoBehaviour
{
Text text;
public static float timeleft = 120f;
// Start is called before the first frame update
void Start()
{
text = GetComponent<Text>();
}
// Update is called once per frame
void Update()
{
timeleft -= Time.deltaTime;
if (timeleft < 0 )
timeleft = 0;
text.text = "timeleft: "+ MathF.Round(timeleft);
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.UI;
public class countdown : MonoBehaviour
{
Text text;
public static float timeleft = 120f;
// Start is called before the first frame update
void Start()
{
text = GetComponent<Text>();
}
// Update is called once per frame
void Update()
{
timeleft -= Time.deltaTime;
if (timeleft < 0 )
timeleft = 0;
text.text = "timeleft: "+ MathF.Round(timeleft);
}
}
If you want to use it with unity, you need to have that
the error is from the other script
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class gamecontrol : MonoBehaviour
{
public GameObject timeisup;
// Start is called before the first frame update
void Start()
{
Debug.Log(countdown.timeleft);
}
// Update is called once per frame
void Update()
{
if (countdown.timeleft <=0)
{
Time.timeScale = 0;
timeisup.SetActive(true);
}
}
}
This is not properly, but ok. What is line 26
It worked finer without this extension
I had to reinstall it to get it to work
text.text = "timeleft: "+ MathF.Round(timeleft);
text is null then...
i will eat my lunch and come
But I thoight the error said the other script
Yes, it is from countdownscript
(A terrible name)
So what is line 26 of THAT
I assume it is what I initially said. timeisup is null
i guess countdown is the class name but the script name is still countdownscript ?
It cannot work without that extension.
i question your standards of "it works fine"
everyone who says that, usually has no idea what they're looking at is not normal
I need to make a website for all this graveyard info unity is breaking each iteration of the website..
half their shit now is 404
"Oh you want link to this Netcode example project.? FFF UUU here's a 404 "
🙂
this is the nodes that are used
time left - countdown
game control - game control
your issue is simple
text = GetComponent<Text>(); this aint workin
only few possibilities
- Your Component is probably TMP_Text and not Text
- if it was Text, it certainly isn't on this same object
yeah it`s textmeshpro
new code for countdown
so are you using the Mesh version of TextMeshPro ?
UI Text Mesh is TextMeshProUGUI. There's also the shared parent class TMP_Text that works for either.
the point is ....?
Use that Type
the stack, was overflowed 😏
Stack Overflow is when the number of recursive calls exceeds the maximum
i realise i was calling the game manager to execute itself instead of something else
on macOS, unity just dies instead of correctly breaking the infinite recursion
yeah usually if you got something recursive
very annoying
i was doing this on the GameManager script lmao
wow, macOS is weak . . .
well also windows can't force quit apps like macos can, so you gotta take your wins when you can
at least, not from the right click menu
Im looking to create a buggie/cart system that can transport plants/pots around. Before I reinvent the wheel and beat my head against the wall fixing some code, is there a better way to think about this?
oh dang
one sec ill show the setup i have now XD
do you plan on using physics ?
yes, I gotta show you the game to give you context, darn unity community for no vid chat lol
gotcha
there is video upload
one sec 😄
if you hit limit put it on https://streamable.com/
im getting close to complete determinism
i feel like i can probably start working on online multiplayer soon
man..determinism on multiplayer is tricky
well anything on multiplayer is like 100x harder
Hi guys!
I need a script that somehow plays a jumpscare on touch of a trigger. Somehow like the player’s moveme gets disabled on touch of the trigger and the player’s camera and a model plays an animation. I’m very new to C#. If someone has or can provide an example script, I’d be very thankful!
The main hurdle with rollback networking (in my inexperienced eyes, at least) is going to be dealing with object creation/destruction
imagine a projectile hits a target, and then you get rolled back and the projectile actually missed
it has to come back to life
Also note that rollback basically does not work with more than two people
yeah it is 4 player 😭
up to at least
yeah, you're introducing more and more room for problems as you add more players
I'd start with really basic networking: add X frames of delay
I ran into the exact same limitaion with your exact use case. Most Smash-likes have rollback for 1v1s and delay-based for FFAs
i had it a seperate way where it was fixed on the y axis and wouldnt clip, but vid was too long i cut it down. the type mismatch isnt a big deal, i was in the midst of changing it from transform to game objet when taking the vid
It won't feel great, but it will be very easy and very reliable
So what's the exact problem with lots of players? Is it that you wind up rolling back on pretty much every frame?
why wouldnt rollback work for ffas?
Yeah, the rollback computation ends up taking so long that by the time it's done you have already missed the frame and need to roll back again
ah
i see
i mean, im not going for a super tight experience, here
i just want something that works lol
Is it more about the rollback simply taking too long to simulate?
I mean, it's possible, but you'd need each player to have fantastic ping.
I think i need to redo my place and grab scripts. those were from a tutorial about 4 months ago, and easily understood, but i dont think it can be used for everything like it is right ow
i'm not sure if this is "each rollback costs too much" or "you do too many rollbacks"
how exactly do you want to push the cart?
physics or just like fixed
i found this cool multiplayer library which advertises needing to write minimal netcode, and supports things like rollback which im going to have a look at
I want it to be fixed, but navigated by the player. Just dont know how, or thinking too hard
what kind of netcode does stuff like call of duty or games like that use? not rollback im assuming
It's the second one. Since you're getting input from multiple players, it's possible that during the process of resimulating a rollback, you end up needing to do another rollback because someone else's packet comes through
yeah just parent it to the player then
make a specific transform for it maybe so its easy to align
everything else seems is just a bunch of parenting
plants parented to cart, cart parented to player
It has the possibility of completely blowing out your buffer and you end up falling back to delay-based right away.
ah, I see
Is it okay if I store the quantity of Items I have directly in my inventory slots?
Waiting for every player to send their packet before doing a rollback is exactly the problem rollback is supposed to fix
perfectly fine if its own class
I personally have a Slot manager for all my Slot
have u made a smash fighter too? i havent seen many of those on itch and stuff like that so im interested
oh, okay, thanks
probably because its very diffcult
I abandoned a smash fighter long ago
Navarone stop. please dont tell me it was that easy hahaha
I got scooped, basically.
haha yeah I mean . if you don't want physics cart, I would've made it more difficult by using Raycasts to "hover" the cart
Someone made my idea but with a budget
bro im overengineering so hard
however I am confused because if I have one UI representation of my inventory I can´t have two of them because one canvas has all those slots and whenever I create another, the slot value dissapear
local multiplayer isnt too bad but online is probably terrible lol im just interested
thats the part that makes it diffcult
ah damn :/ im just doing this for the love of the craft i guess im not expecting it to get popular
I need raycasts to place items on the array inside the cart, but THAT is difficult in itself... thats the whole thing behind supermarket sim i cant understand yet
i wanted to put it on steam but im usin so many sound effects ripped from smash and guilty gear im probably not allowed lmao
why do you need multiple canvas, I'm confused there. Are you inventory slots not an Object ? like Slot etc.
here is my inventory canvas, if I duplicate it, the objects don´t apperar
It was basically Smash MUGEN
https://projecttussle.com/
But Fraymakers came out with a robust character editor and I had basically made an unmaintainable mess so I just decided to scuttle it
yeah, ItemSlot I called it
yeah so why do you need to duplicate anything
because if I want to have another representation of my inventory
what does that even mean lol
You should never design UI first then Code
oh i saw videos about fraymaker, sucks that happened to you
always make ur inventory logic first, then you can replicated it in UI or whatever @ionic zephyr
yes, but my doubt is that my inventory depends on the slot information
exactly so why does the UI need to do any logic at all or canvases
Is it better doing the inventory with solely code?
what else would you use ?
It's fine, I had already been spinning my wheels for months at that point. And I'm just glad that someone was able to make it
I mostly wanted to make it because I wanted to play it
I meant the design
Like where each slot will be etc
my suggestion was simple, don't design your inventory logic around your UI. The opposite, make your logic first work then put the visuals on it
hm what I understand is that you just slap components on a canvas. Thats what UI means for me. I cannot comprehend how you could design logic around it
I do not have enough experience with uis probably thats why I dont get it.
Just wanted to ask because I'm also trying to make my inventory system work.
fair enough. What kind of netcode would an fps and stuff use? is there a name for that sort of framework?
You can put components on anything!
including components you wrote
and you can instantiate prefabs from code
My game's UI is largely generated through scripting
Why may I ask?
I have seen people doing that as well
so i have 2 levels but when i load level 2 the music from level 1 plays over the level 2 music
There's no reason to manually set up 20 different sliders for 20 different settings
I have prefabs for things like "a button that takes you to another menu screen" and "a way to edit a float"
I have an ItemSlot class and I created a slot prefab with that script. Those prefabs are child of an Inventory Canvas. Now, lets say I want to do another canvas that has the SAME information as the previous one, how could I do that?
I don't put any components(Scripts) in UI. maybe only each slot has a Slot script for Slot Manager creates them at runtime, but I generally find it cumbersome to put Scripts on UI objects they are hard to find
Ah okay. So that must be why people prefer that indeed
Basically, I hand-author whatever I can't describe through code, and then automatically generate the rest
Delay-based
for a first person shooter?
they usually try to preview as much as possible on the client (including your movement) immediately
lots of Client Side Prediction
that's a whole can of worms I have yet to open
i guess it's just another way to separate game state from the presentation
i have a problem building my game, where can i get help, i'm a bit lost in this discord
thank you
If you have more than one place that you have to change something, errors become possible. So if you have to:
- create a new setting
- add a new item in your settings menu for that setting
then you can forget to do the second one, and now you have a missing setting
There's essentially two "kinds" of netcode, rollback and delay based. There's a lot of optimizations and prediction models you can graft onto them, but the core difference is "How do you deal with the situation where someone's data isn't in yet". Your options are either "wait for them and resync" or "roll back to the last known good state and resimulate". That's why you'll see laggy players in shooters kind of pop around like they're teleporting
"delay based networking" makes me think of a game that does nothing with your input for several frames, and that completely stalls if input isn't received from the other player
i think this coherence library might be a winner, it looks like it does a lot of the heavy lifting for me, plus if i just use peer-to-peer i dont have to pay their stupid pricing model
Imagine I have two Canvas in which I want to show the inventory information (maybe one vertical and one horizontal), I have a Slot prefab that has a ItemSlot script that stores the information. Also I created an InventoryManager with a list of ItemSlots that stores the information of all the slots. How can I make sure that on both Canvas the information is the same?
It means that if you input an action on Frame 30, and it takes 2 frames to reach the host, then the host will have you doing that action on Frame 32. A rollback system will have you basically appearing 2 frames into your action on Frame 32
ah, i see
Initialize them with the same data.
how? from the ItemSlot script?
The same way you initialize one inventory canvas
Or, if it's a convoluted mess, just copy the slot data from one place to another
@swift crag im thinking for projectiles and stuff i give each projectile an ID and then maybe store a dictionary or something of each projectile in the current state, idk if that solves the issue with instantiation and deletion, though. maybe if the dictionary doesnt contain an entry for a projectile it gets deleted, or if there is a projectile missing it creates the projectile with the velocity and everything?
first decide if you're actually doing rollback (:
if you aren't then none of this is really necessary
would rollback be hard to implement retroactively
might start with delay based then make rollback when im more experienced
The difficulty would be in your visuals/sound/etc.
It's pretty easy to just go back to an old game state and then run a bunch of ticks
But you have to then sync the visuals, particles, sound effects, and other such things back to the new game state
this is where you enter
territory
I linked a GDC talk that was about rollback netcode implementation
A huge part of that was things like visuals and object creation/destruction
whats it called? i'll have a watch later
In this 2018 GDC talk, Netherrealm Games' Michael Stallone describes the drastic engine changes, optimizations, and tools that are involved in rolling back and simulating up to 8 game frames in 16ms in games like Mortal Kombat and Injustice 2.
Register for GDC: https://ubm.io/2yWXW38
Join the GDC mailing list: http://www.gdconf.com/subscribe
...
this is just straight up wrong, if you enter the article it says it doesnt use it lmao
I think the problem is that there wasn't enough AI involved
true
I often keep inventory logic and manage inventory data in an InventoryController script, which gets added to the GOs representing objects with inventories (player, chest, etc.). InventoryController has no knowledge of or logic for any UI.
Other scripts are solely dedicated to displaying inventory data and handling user interaction. When supplied with an InventoryController instance, they'll instantiate slot UIs and hook up event handlers and such. These UI controller scripts can also subscribe to events that the InventoryController emits to keep their visuals in sync if the inventory data changes.
In this fashion, there is only copy of the data ("single source of truth"), and because the code storing and managing the inventory data is separate from the code which displays it (separation of concerns), you can create however many different visual representations and interfaces for the data as you desire without complicating data access/management.
Yeah, you are right, thanks for the advice
Hey guys. Need some help debugging this animation set-up that i have
i have a mono behaviour animation component to handle hashing and calling animations crossfades:
public float Attack() => PlayAnimation(AnimationNames.Attack);
private float PlayAnimation(AnimationNames animhash)
{
animator.CrossFade(animationDuration[animhash].hash, crossFadeDuration);
return animationDuration[animhash].duration;
}
then, in another mono behaviour in the same gameobject, im calling its functions, for instance:
public IEnumerator Attack()
{
if (canAttack)
{
canAttack = false;
billboard.lookDir = (attackTarget.transform.position - transform.position).normalized;
float animTime = animations.Attack();
StartCoroutine(weapon.Attack(attackTarget, new Damage(this, 10)));
yield return new WaitForSeconds(animTime);
StartCoroutine(ResetAttack(animTime));
}
}
The thing is. the attack animation never really plays. even by looking at the animator, the state never runs and i dont know why. the code is calling correctly the function
The game object does whatever the script says
Thank you ❤️
Well then I'm in a parallel universe XD
BTW why is this code broken?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class matarzak_aiming_idle : MonoBehaviour
{
public Camera cam;
Vector2 mouseposition;
public Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
mouseposition = cam.ScreenToViewportPoint(Input.mousePosition);
}
void FixedUpdate()
{
Vector2 aiming_direction = mouseposition - rb.position;
float aiming_angle = Mathf.Atan2(aiming_direction.y, aiming_direction.x) * Mathf.Rad2Deg - 90f;
rb.rotation = aiming_angle;
}
}
that's irrelevant also you need a configured IDE if we outta help you.
..also that snake casing 😬
I followed every step of the tutorial but the rotation is just... bad
mouseposition and rb.position are in completely different spaces
mouseposition is in viewport space
rb.position is in world space
you need to use ScreenToWorldPoint to get a world space mouse position
you copied wrong or tutorial is bad
or both
Well
As soon as I installed the extension I got errors
2 big errors
One, the version of it is old ( the error message says so)
And the second one is that it tries to download. NET via terminal ( output ) while it is already installed
That's why this extension troubles me
If the error message says that it's an old version of the extension, you should install an up to date one instead
Notification newNotification = Instantiate(notification, notificationGroup.transform).GetComponent<Notification>();
newNotification.messageText.text = Message;
newNotification.length = notificationLength;
does this code get run before newNotification.start gets run?
so you just ignore erros and move on or actually try to fix problems..
Start runs in the next frame.
So it runs befoe Start, yes (but after Awake)
The latest version is 1.0.2 for me
Is it the latest version?
I sure do want to fix the problems, but as soon as I download that extension I got 2 times more errors, which do cause trouble, uncontrolled trouble
Follow the instructions exactly. !ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
idk even know what "uncontrolled trouble" means thats very vague.
if you find errors, fix them. If you dont know what they mean look them up. You should be in control of your machine
No, it just either wasn't configured properly and you didn't realize, or it WAS installed and you didn't realize.
You have not followed the instructions I linked.
Follow every single step on the page
You have an old version of the Visual Studio Editor package installed. The instructions tell you to update it.
The warning also told you exactly what to do.
Follow every single step exactly. Do not skip anything.
OK, I will
yup simple fix, its in the guide
this is atrocious, you should as a gamedev know how to take screenshots..
Hello, the objects collide but nothing happens can I get some help figuring out why: using UnityEngine;
public class cchange : MonoBehaviour
{
public Camera mapcam;
public Camera battlecam;
void Start()
{
mapcam.gameObject.SetActive(true);
battlecam.gameObject.SetActive(false);
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Enemy"))
{
// Switch cameras
mapcam.gameObject.SetActive(false);
battlecam.gameObject.SetActive(true);
gameObject.GetComponent<Collider2D>().enabled = false;
}
if (collision.gameObject.CompareTag("Enemy"))
{
Debug.Log("Collided with an enemy!");
}
}
}
The Three Commandments of OnCollisionEnter2D:
- Thou Shalt have a 2D Collider on each object
- Thou Shalt not tick
isTriggeron either - Thou Shalt have a 2D Rigidbody on at least one of them
Define "nothing happens"?
I have 2 scripts one where when both players collide one stops in its tracks
that works fine
this script should make it so
Does it mean that the method is called?
Have you thought about checking it?
"i think so" does not cut it (:
How don't you know it?
When the method is called.. it's basically called
I don't know why do I have to explain it?
Print something in your method and see if the method is called
say no more
Does it mean that you understand or I have to shut up?
Oh, cool one
I don't have vpn on pc
Discord won't even open up
I want to show a score on a leaderboard scene but the text isnt showing
ive been trying for hours 😭
What does it have to do with taking a screenshot?
You have to show the essential parts we need to help you.
Oh I realised
Sorry I'm just dumb
very true. i havent asked for help in here in a while gimme a sec sorry
how do I show code in discord btw
this?
ok good
!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.
Great. This is inline code. Use multiline when required.
// your code goes here
rip
is this good?
no
shoot lemme delete it
also large code shoold be a link