#💻┃code-beginner

1 messages · Page 398 of 1

rich adder
#

anyway problem is solved, just a heads up for next time 👍

junior patio
#

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!

strong wren
#

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

rich adder
mild onyx
strong wren
#

i worked so hard on this project 😩 i did so much and its only my 3rd

raw token
#

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.

stuck palm
#

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

mild onyx
rich adder
raw token
stuck palm
verbal dome
#

I didnt even know that you can make default components readonly like that capsule

rich adder
#

is there some other custom editor script maybe for the capsul?

stuck palm
verbal dome
#

Is there any component above the capsulecollider? I wonder if some custom inspector leaves GUI.enabled = false by accident

raw token
swift crag
mild onyx
#

so GetKeyDown works for pressing a key but what about holding a key? cant seem to find the right thing

mild onyx
#

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

polar acorn
#

Are you setting the Y value of the velocity to something?

mild onyx
#

its verry if'y

polar acorn
#

So whichever one happens last is the one that decides what velocity is

#

They all overwrite the entire velocity

brittle crown
#

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?
raw token
#

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 👀

frozen star
#

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?

olive osprey
#

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!

frosty hound
#

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.

teal viper
raw token
# brittle crown Yo <@1097950947369562187> after it working on the top left, I moved it to the to...

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

brittle crown
#

will try

brittle crown
raw token
#

Yeah alright - I guess that makes me feel a little less crazy... let's see...

brittle crown
#

lol

cosmic dagger
#

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?

remote osprey
remote osprey
#

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.

teal viper
remote osprey
teal viper
#

Or handle the events on the player instead of the cards.

gaunt ledge
#

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

dense root
#

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;
    }
teal viper
teal viper
gaunt ledge
wintry quarry
teal viper
gaunt ledge
#

nop, the one between this and base

#

there is any way to do that?

teal viper
#

Base is the class that this inherits from

gaunt ledge
#

and what if the class that is inheriting this method, has overrided this method from another class?

teal viper
#

The implementation in the base(the direct base class that this class inherits from) would be used.

wintry quarry
# dense root How do I prevent the text from waterfalling over to the next line? Just cleanly ...

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/...

▶ Play video
teal viper
#

It doesn't matter what's up the hierarchy above the base class.

dense root
#

I'm trying to avoid TMP because it makes it difficult to work with Asian characters

wintry quarry
#

You just need a font and a font asset that's properly set up

dense root
#

I can try tinkering with it again, but I ran into some troubles with the character sets be limited IIRC

wintry quarry
#

You have full control over the character sets in your font asset with TMP

dense root
#

Alright I can try again, fingers crossed

cosmic dagger
cosmic dagger
ionic zephyr
#

What can I do to make my crafting system eliminate changes whenever I quit the crafting station without having used my resources?

cosmic dagger
#

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 . . .

modest dust
#

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

ionic zephyr
#

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

cosmic dagger
modest dust
#

Undstandable

#

Either way, if you're transferring your resources from one place to another then.. simply transfer them back.

ionic zephyr
#

I might get the original amount of resources and if the player cancells the crafting, use that information

modest dust
#

There are multiple ways, as long as it works, it's good

ionic zephyr
modest dust
#

By calling a method which cancels it?

ionic zephyr
#

yes, but I have a problem there

modest dust
#

What kind of problem

ionic zephyr
#

My inventory is based on item slots which each have the quantity of each item that the player has

modest dust
#

Yes, and?

ionic zephyr
#

so whenever I use the crafting system if I "place" an object in the crafting station, the quantity is substracted

modest dust
#

Yes, so?

ionic zephyr
#

but what if then I decide I want to quit crafting and want my objects back again?

modest dust
#

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

ionic zephyr
#

yeah, but how?

modest dust
#

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?

raw token
#

@brittle crown I'm at a loss... everything I'm coming up with seems suspiciously convoluted. There has to be a better way

ionic zephyr
modest dust
#

How do you reference the item, how do you subtract from the inventory and how do you add to the crafting station

ionic zephyr
#

_itemsInCraft is an array of Items(ScriptableObjects)

#

_itemImages is an array of Images that show the sprite

modest dust
#

And how do you take the items out of the crafting grid?

#

If that's implemented

ionic zephyr
#

I havent done it yet because I dont know what to do honestly

cosmic dagger
ionic zephyr
modest dust
ionic zephyr
#

leave a hole

modest dust
#

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

modest dust
#

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

ionic zephyr
#

could you write a brief example?

dense root
#

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

https://gdl.space/ehedosaqiz.cs

#

Does it have something to do with the coroutine?

modest dust
eternal needle
ionic zephyr
modest dust
#

Is there one item per crafting slot?

ionic zephyr
#

yes

modest dust
#

Then what about it

ionic zephyr
#

oh okay

#

let me see

modest dust
#

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

ionic zephyr
frosty hound
#

Are you using two accounts or something? 🤔

ionic zephyr
#

what

#

oh sorry

ionic zephyr
timber tide
#

is it on the scene

soft anvil
#

because of "box collider" is not Collider 2D

timber tide
#

oh is that a 3D version?

#

should really just call the 3D version cube collider ;p

cosmic dagger
#

Check your code. It should die or call a method to be destroyed . . .

soft anvil
#

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

cosmic dagger
#

You never call RemoveEnemy . . .

#

You never call the method RemoveEnemy. That's why the GameObject does not get destroyed . . .

soft anvil
#

I think animator.Settrigger("Defeated") will call RemoveEnemy()

cosmic dagger
#

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 . . .

soft anvil
#

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

cosmic dagger
#

Then what did the tutorial do? You have a reference to against . . .

rotund forum
#

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)

teal viper
#

So in the tutorial it doesn't work as well?

rocky canyon
#

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

rotund forum
rocky canyon
#

w/ the ignore layer selected

#

wait. let me backup.. i dont know what ur doing

rotund forum
rocky canyon
#

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

amber isle
#

Would it be smart to have a separate controller for projectiles, explosions, cannon movement? Or should I combine them all into one controller?

rocky canyon
rocky canyon
#

in ur case (1) controller that could fire many different projectiles (the projectiles could spawn the explosions)

cosmic dagger
#

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 . . .

pure pike
#

can someone help me change the target sdk for android from 34 to 32

pure pike
#

sry

rich adder
#

anyway it should be in the project settings afaik

cosmic dagger
#

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 . . .

edgy forge
#

is this the right way to find this component?

var textMeshProComponent = GameObject.Find("ProgressText").GetComponent<TMPro.TextMeshPro>();```
#

it's coming back null

ivory bobcat
rocky canyon
#

if the script is on the text element u could use GetComponent<>(), or that ^

#

wouldnt recommend Find unless its absolutely necessary

edgy forge
#

the script is not on the text element

rocky canyon
#

then do what Dalphat mentioned

edgy forge
#

just out of curiosity, is the component type wrong?

rich adder
#

yes

#

you need TMP_Text (this one is shorter and works for mesh one as well its base class)

#

or TextMeshProUGUI

ivory bobcat
#

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.

lone hamlet
eternal needle
#

though i do find it odd you need to have another layer which also ignores raycasts

rotund forum
#

😅

rotund forum
iron wing
#

how can i change the game's camera?

polar acorn
iron wing
polar acorn
iron wing
polar acorn
iron wing
eternal needle
charred spoke
#

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.

iron wing
# eternal needle if you're referring to multiplayer then you definitely shouldnt be doing multipl...

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.

iron wing
charred spoke
#

Also are you trying to create a system where you can view other players pov’s sorta like counter strike when your dead ?

iron wing
charred spoke
#

Well yes

#

How ever you can still get the camera when you instantiate your player

iron wing
charred spoke
#

There is a handy GetComponentInChildren

charred spoke
static cedar
#

I'm thinking of extending Transform, is there a reason it's not a good idea? UnityChanThink

iron wing
rocky canyon
#

you just change the type ur looking for

charred spoke
iron wing
rocky canyon
#

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

iron wing
#

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.

charred spoke
#

GetComponentInChildren is recursive it will search all children untill it finds a suitable component

#

The level of nesting does not matter

iron wing
#

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

hallow iris
#

!code

eternal falconBOT
hallow iris
astral falcon
astral falcon
#

do you ever assign a material to it?

hallow iris
#

i am trying to do a raycast but it is being weird

#

at the moment it is only a mesh and a mesh renderer

astral falcon
#

So please take your time and write down, what you are expecting and whats not working.

hallow iris
astral falcon
#

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

astral falcon
#

I suggest you to look at your generated mesh in wireframe mode, which will tell you more about your topology

humble summit
#

Where can I find accurate documentation describing how to attach a value changed handler to a UnityEngine.UIElements.Slider?

pure pike
#

im very bad at coding so can someone help me make it so when i touch a block in game the timer stops

pure pike
humble summit
#

add a bool, branch the logic when bool == false

pure pike
#

huh

#

i dont understand code very well, im still learning (thats why i came to code BEGINNER)

humble summit
#

void update(){
  if(!timerStopped){
    //do timer logic
  }
}

void whenYouTouchABlock(){
  timerStopped = true;
}
pure pike
#

where do i put it

#

hold on

humble summit
#

you can't have two Update()

pure pike
#

oh

humble summit
#

You will want to do some C# tutorials

pure pike
#

like this then right

burnt vapor
# pure pike 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;

humble summit
#

You may want to put lines 28 and 29 inside the if

burnt vapor
#

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

humble summit
#

That will work, assuming that you have no other logic in Update that needs to run when timerStopped == true;

burnt vapor
#

They don't

#

Otherwise I would advice you make a new method for the draw logic and do the same thing

pure pike
#

what

burnt vapor
#

In general you should not apply logic in Update, only call methods from that have have individual taks

pure pike
#

i have 0 experience in coding

#

i dont even know what yall are even talking about

burnt vapor
#

Unity is a whole other thing and it will be very confusing to learn two separate things

#

Unity does a lot different

pure pike
burnt vapor
#

Right now you try to learn both C# and Unity, and this is very confusing

pure pike
#

right now i wanna get the game out, not learn c#

humble summit
#

lol

burnt vapor
#

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

pure pike
#

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

burnt vapor
#

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

pure pike
#

I ALREADY SAID THAT

#

I CANT CODE

humble summit
#

then you can't make a game

burnt vapor
burnt vapor
#

I don't really understand why somebody who doesn't have any idea on how to code, works on code

pure pike
#

you wanna see my game

burnt vapor
#

Are you a single person trying to make a game?

pure pike
#

this is my game, you think a have a team

burnt vapor
#

And everything in here is copy pasted scripts from other people while you have no knowledge on how these work?

pure pike
#

i sorta know how everything works

#

but not well

burnt vapor
pure pike
#

i mean ive done very little 2d coding (while following tutorials) but not 3d

#

are u gonna help me or not

burnt vapor
#

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

humble summit
#

Do you know where can I find accurate documentation describing how to attach a value changed handler to a UnityEngine.UIElements.Slider?

pure pike
humble summit
#

lol

pure pike
#

i just wanted help

fossil drum
humble summit
burnt vapor
humble summit
fossil drum
humble summit
fossil drum
#

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.

humble summit
#

slider.RegisterCallback<ChangeEvent<float>>((e) =>{Debug.Log("callback")});
also does not work

fossil drum
#

What does it say then?

humble summit
#

I'll check out that project and hopefully find something

fossil drum
#

does not work is useless for a programmer, give some context like the stacktrace or the error description at least.

humble summit
#

I did not say there is an error.

fossil drum
#

So it does work, but it doesn't write the log?

humble summit
#

The expected behaviour is that it would write to the log, but it does not.

kind tartan
fossil drum
#

And where do you register that callback then? Show your full code.

humble summit
kind tartan
#

My guess you passing not corect visual element.

humble summit
#

yeah that seems it

#

gonna test now

kind tartan
#

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");

humble summit
#

        if (musicVolumeSlider == null) {
            throw new Exception("slider should not be null");
        }

        musicVolumeSlider.RegisterCallback<ChangeEvent<float>>((e) =>
        {
            Debug.Log("musicVolumeSlider.RegisterValueChangedCallback");
        });
kind tartan
#

sliderMusicVolume is not sliderI think. It is parent obect, which have slider inside of it. at least it was two years ago

humble summit
#

"sliderMusicVolume > VisualElement"?

kind tartan
#

how does it look like on your end. does it have visual element icon or slider icon. depends on that.

humble summit
#

looks like I need to get the child VisualElement, perhaps

kind tartan
#

maybe try Q<Slider> instead (Slider)<..>.Query("sliderMusicVolume");

#

it should be the same tho

humble summit
#

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

kind tartan
#

you should get the Slider it self for the change trigger

humble summit
#

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.

kind tartan
#

just in case. you low and high values are set to be 0 and 1 right? not the same>?

humble summit
#

high value is 100

#

I think this component comes with UI Toolkit

#

or maybe I made it and forgot

kind tartan
#

have you checked if musicVolumeSlider is not null, just to learn if it finds correct element

humble summit
#

no, I see Slider in the standard controls

humble summit
fossil drum
# humble summit Start

Yeah seems valid to me.
Can you show a console screenshot? Your not hiding your messages right?

humble summit
#

nothing hidden

#

not much in the console

#

start is definitely executed

fossil drum
#

So that 'caller' is in the same start as your callback?

humble summit
#

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);
            });
        });```
fossil drum
#

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?

ivory bobcat
#

Could probably convert the query to a list and check the count just for debugging purposes

humble summit
ivory bobcat
#

Although getting no log simply implies an empty list already

#

Maybe the line of code never executes?

humble summit
#

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

humble summit
#

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.

languid spire
teal viper
humble summit
frank zodiac
#

is this the correct way to get a random value in a range of 3?

languid spire
frank zodiac
languid spire
#

read the docs

frank zodiac
#

thanks

humble summit
#

I would do some testing with that and see what the results are anyway. I don't trust documentation.

languid spire
humble summit
languid spire
eternal needle
#

If you cant trust the documentation on something simple like a random number, that's a reading comprehension issue

humble summit
#

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

fading seal
#

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

humble summit
#

Use the collider to play an AudioClip with an AudioSource

fading seal
humble summit
#

You would write the C# that would use the collider to play an AudioClip with an AudioSource

fading seal
burnt vapor
eternal falconBOT
languid spire
fading seal
#

do i just copy it?

languid spire
#

no, you do not. You read it again and again until you do understand it, it's pretty simple

burnt vapor
# fading seal do i just copy it?

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

burnt vapor
fading seal
burnt vapor
#

If there's a specific step you have issues with, feel free to ask

burnt vapor
#

Configure your IDE first please

fading seal
#

i thought i duid

#

did

burnt vapor
#

It would correctly highlight more parts of the code if you did

#

Perhaps you missed a step

humble summit
#

real developers use Notepad

fading seal
humble summit
#

lol

eager spindle
#

dumb question but is there any shorthand for getting the screenwidth and screenheight as a Vector2 or Vector3?

fossil drum
eager spindle
#

🫡

#

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

languid spire
#

why would you use a Vector3 for a 2 dimensional space?

eager spindle
#

its really just to store the object's destination position, vector2 works too

tender stag
#

i need to make a custom serializer for my ItemData

#

how does one do that

vast vessel
#

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.

burnt vapor
#

Is this for saving data?

tender stag
#

no

tender stag
#

fishnet needs a custom serializer

#

because it doesnt know what to do with it

hallow iris
#

!code

eternal falconBOT
tender stag
#

nevermind

#

i decided im just gonna pass in the models

#

instead of the actual class

hallow iris
hexed terrace
#

That sounds like your OnCollisionEnter2D isn't being triggered

long jacinth
#

how do i make this so i can use it in other functions and stuff

hexed terrace
#

make it a non-local var

#

(a class level field/ variable)

long jacinth
hexed terrace
#

local means it is encapsulated within a method

long jacinth
#

so i have to mention it at the start

#

"public sprite FirstWeapon;"?

hexed terrace
#

private Sprite firstWeapon; - doesn't need to be public.

long jacinth
#

ok thank you i will try it

#

it works now thanks

burnt vapor
long jacinth
burnt vapor
cosmic dagger
burnt vapor
#

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

cerulean rampart
#

can someone help me ? i cant put waypoint in my car prefabs

cosmic dagger
#

more info is needed. do you have any code?

cerulean rampart
#

yeah

hexed terrace
#

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

eternal falconBOT
cosmic dagger
#

!code

eternal falconBOT
cerulean rampart
#

ty

cosmic dagger
#

did you change the type of the variable?

eternal falconBOT
cerulean rampart
#

omg im sorry

hexed terrace
#

lol

#

!code is the bot command, you're supposed to read the msg it spits out at us :p

eternal falconBOT
cerulean rampart
#

hold on lol

#

💀

cosmic dagger
#

use one fo the sites . . .

cerulean rampart
#

like this?

#

i cant put my waypoint in car prefabs

edgy shard
cerulean rampart
languid spire
#

if that is a GameObject, you cannot assign GameObjects to Prefabs

cerulean rampart
#

:((

cosmic dagger
#

you have to assign it after the prefab is instantiated in the scene . . .

languid spire
edgy shard
#

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");

edgy shard
#

sorry 😦

cerulean rampart
#

it say like this

#

@edgy shard

languid spire
cerulean rampart
#

what should i replace public Transform[] waypoints; to ?

languid spire
#

you should read the API

cerulean rampart
#

can u help me :v

languid spire
#

'FindGameObjectsWithTag' - Objects is plural. So you need something similar but singular

cerulean rampart
#

ok i fixed thx everyone

#

Thanks everyone so much :D

#

this is my first time so im very stupid

vast vessel
#

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.

swift crag
#

0.5ms is pretty darn reasonable

#

that would let your game run at 2000 FPS if you had no other things taking up frametime

wintry quarry
#

if you meet your framerate targets with a reasonable buffer, then you're good

teal viper
vast vessel
#

is 120 good for a qhd monitor on the target hardware, with max settings?

vast vessel
wintry quarry
#

We can't tell you what to be satisfied with

teal viper
#

Which means you have a frame budget of 16.6 ms

vast vessel
#

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()

swift crag
#

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

rocky canyon
#

just buff up the system requirements

#

ez pz 😅

eager spindle
#

also surely there's gotta be a better way to test on a low end device than buying one

lost hamlet
#

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

eager spindle
#

im just thinking if my game needs too much compute especially since its for mobile

vast vessel
#

my targeting system dosnt run every frame but the fsm does.

#

im using the unity hsfm package for that

swift crag
#

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

vast vessel
#

does the job system just split tasks into different threads?

swift crag
#

It helps you run code on worker threads, yes

fading seal
#

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

eternal falconBOT
fading seal
wintry quarry
#

Do it again

#

you missed something

fading seal
#

ok

wintry quarry
fading seal
#

thanks

fading seal
fading seal
eager wolf
#

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

wintry quarry
#

you can print when the instantiate happens and when this Start method is called

#

so you can see what order that happens in

eager wolf
wintry quarry
#

why is that weird

wintry quarry
eager wolf
#

because CheckForFuel is also run on Start

wintry quarry
#

that doesn't make sense

#

something is missing here

#

logs will help

#

or the debugger

frosty hound
#

Are you getting a null reference?

eager wolf
# wintry quarry Again - debug your code

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

eager wolf
wintry quarry
#

what makes you think it's not being found

eager wolf
#

it says "Missing" rather than "None"

#

not sure if that helps

wintry quarry
#

Perhaps the code inside CheckForFuel is destroying it

#

that would explain why swapping the location of the code causes it to be found

eager wolf
#

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)

wintry quarry
#

Anyway there's definitely more to the puzzle here than what you shared

eager wolf
wintry quarry
#

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.

late burrow
#

how to read bitwise

#

if 7 contains 4

wintry quarry
#

wdym by "if 7 contains 4"

rich adder
late forum
#

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.

rich adder
#

also which app gives you error

late burrow
#

i want check for 4 bit

rich adder
#

isn't that what AND is for?

late forum
wintry quarry
late burrow
#

yes

#

so if number contains 4

wintry quarry
late burrow
#

without >>

wintry quarry
#

(this example is checking in a byte but it works the same in int or long)

late burrow
#

i wont understand these at all

wintry quarry
#

try to learn

late burrow
#

but i didnt needed to set them

#

i just did |= number

late forum
#

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

wintry quarry
#

<< is simple.

1 is 00000001
1 << 3 moves all the bits over 3 times:
so 00001000

late burrow
#

cant i read same way

elfin cedar
#

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?

wintry quarry
# late burrow cant i read same way

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;
late burrow
#

yes i know just | is much easier

wintry quarry
#

also the same as:

int mask = 0b100;
int masked = myNumber & mask;
bool contains4 = masked != 0;```
late forum
# rich adder no idea what that means

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?

languid spire
#

there is a simpler way

[Flags}
enum MyInt {
 isFour = 1 << 3
}
...
int i = 7;

if (((MyInt)i).HasFlag(isFour)) ...
rich adder
late forum
# rich adder 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 "

rich adder
#

have you removed the VSCode Editor package from Unity package manager

#

try also regen project files

late forum
late forum
rich adder
rich adder
rich adder
late forum
rich adder
#

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 vscode

late forum
#

OK

#

Thanks

elfin cedar
#

Is this why my Visual Studio crashes? I click console errors in unity, it opens all the way up, and then it closes

rich adder
elfin cedar
#

Microsoft Visual Studio 2022

rich adder
#

yeah try reinstalling everything VS related then

#

it should not be crashing

elfin cedar
#

So Uninstall VS and then reinstall? Okay thanks

rich adder
#

that be the first I'd try

late forum
rich adder
polar acorn
rich adder
#

don't think Visual Studio uses the internet while in use (maybe once for activating license)

late forum
rich adder
#

ohhh right.

late forum
#

The last time I saw the installation page it was like 17 gb
17 GB!

hexed terrace
#

VS install depends on what components you install with it

#

The file you download from the site is an installer, it's tiny

rich adder
#

yeah VS with bunch of workloads and I'm at almost 70+ GB

#

iirc MAUI alone was like 20GB

hexed terrace
#

Mine's 4.5 GB

rich adder
#

wait, with all workloads? 😮

hexed terrace
#

with whatever is reqiured for Unity to run, nothing more

rich adder
#

ohh ok

hexed terrace
#

so.. C++ and the game one?

rich adder
#

was about to say lol some of the workloads are taking way too much space for mytaste 😦

late forum
cosmic quail
hexed terrace
#

add support for various things

summer stump
hexed terrace
rich adder
#

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

late forum
#

I should have never installed unity extension

swift crag
jagged socket
#

that is all because i want to make a countdown 🥲

late forum
#

The whole thing started again

rich adder
rich adder
#

start by using proper naming conventions

#

isn't a requirement but it will help your own code later on..

summer stump
jagged socket
# summer stump > 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);
    }
}
summer stump
rich adder
jagged socket
#
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);
        }     
    }
}

summer stump
late forum
rich adder
#

wait you changed the names, in error it says countdownscript

#

ffs

#

text is null

jagged socket
summer stump
#

text is null then...

jagged socket
#

i will eat my lunch and come

summer stump
#

But I thoight the error said the other script

rich adder
#

me too

#

their bad naming prob

summer stump
#

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

rich adder
#

i guess countdown is the class name but the script name is still countdownscript ?

summer stump
rich adder
#

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 "

jagged socket
#

this is the nodes that are used
time left - countdown
game control - game control

rich adder
#

only few possibilities

  1. Your Component is probably TMP_Text and not Text
  2. if it was Text, it certainly isn't on this same object
rich adder
#

well then there you go

#

Text != TMP_Text

#

use the latter

jagged socket
#

new code for countdown

rich adder
jagged socket
#

yeah

rich adder
#

thats not the mesh version

#

it says UI right there

#

UI doesn't render mesh

polar acorn
#

UI Text Mesh is TextMeshProUGUI. There's also the shared parent class TMP_Text that works for either.

rich adder
#

damm even hinted the name twwice, i should've been specific 😢

jagged socket
#

the point is ....?

polar acorn
#

Use that Type

stuck palm
#

what is a stack overflow exception?

#

i only know the website

rich adder
#

the stack, was overflowed 😏

willow scroll
stuck palm
swift crag
#

on macOS, unity just dies instead of correctly breaking the infinite recursion

rich adder
#

yeah usually if you got something recursive

swift crag
#

very annoying

stuck palm
#

i was doing this on the GameManager script lmao

cosmic dagger
#

wow, macOS is weak . . .

rich adder
#

well also windows can't force quit apps like macos can, so you gotta take your wins when you can

swift crag
#

at least, not from the right click menu

vale karma
#

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?

rich adder
vale karma
#

one sec ill show the setup i have now XD

rich adder
vale karma
#

yes, I gotta show you the game to give you context, darn unity community for no vid chat lol

rich adder
#

gotcha

vale karma
#

one sec 😄

rich adder
stuck palm
#

im getting close to complete determinism

#

i feel like i can probably start working on online multiplayer soon

rich adder
#

man..determinism on multiplayer is tricky

#

well anything on multiplayer is like 100x harder

neon latch
#

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!

swift crag
#

imagine a projectile hits a target, and then you get rolled back and the projectile actually missed

#

it has to come back to life

polar acorn
#

Also note that rollback basically does not work with more than two people

stuck palm
#

up to at least

swift crag
#

yeah, you're introducing more and more room for problems as you add more players

vale karma
swift crag
#

I'd start with really basic networking: add X frames of delay

polar acorn
vale karma
#

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

swift crag
#

It won't feel great, but it will be very easy and very reliable

swift crag
stuck palm
polar acorn
stuck palm
#

ah

#

i see

#

i mean, im not going for a super tight experience, here

#

i just want something that works lol

swift crag
polar acorn
#

I mean, it's possible, but you'd need each player to have fantastic ping.

vale karma
# rich adder there is video upload

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

swift crag
#

i'm not sure if this is "each rollback costs too much" or "you do too many rollbacks"

rich adder
#

physics or just like fixed

stuck palm
#

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

vale karma
#

I want it to be fixed, but navigated by the player. Just dont know how, or thinking too hard

stuck palm
#

what kind of netcode does stuff like call of duty or games like that use? not rollback im assuming

polar acorn
rich adder
#

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

polar acorn
#

It has the possibility of completely blowing out your buffer and you end up falling back to delay-based right away.

ionic zephyr
#

Is it okay if I store the quantity of Items I have directly in my inventory slots?

polar acorn
#

Waiting for every player to send their packet before doing a rollback is exactly the problem rollback is supposed to fix

rich adder
#

I personally have a Slot manager for all my Slot

stuck palm
ionic zephyr
rich adder
polar acorn
vale karma
polar acorn
#

I got scooped, basically.

rich adder
polar acorn
#

Someone made my idea but with a budget

vale karma
#

bro im overengineering so hard

ionic zephyr
# rich adder perfectly fine if its own class

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

stuck palm
rich adder
stuck palm
vale karma
#

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

stuck palm
#

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

rich adder
ionic zephyr
polar acorn
#

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

rich adder
ionic zephyr
#

because if I want to have another representation of my inventory

rich adder
#

You should never design UI first then Code

stuck palm
rich adder
#

always make ur inventory logic first, then you can replicated it in UI or whatever @ionic zephyr

ionic zephyr
rich adder
final kestrel
#

Is it better doing the inventory with solely code?

rich adder
polar acorn
#

I mostly wanted to make it because I wanted to play it

final kestrel
#

Like where each slot will be etc

rich adder
# final kestrel I meant the design

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

final kestrel
#

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.

stuck palm
swift crag
#

including components you wrote

#

and you can instantiate prefabs from code

#

My game's UI is largely generated through scripting

final kestrel
#

I have seen people doing that as well

bleak condor
#

so i have 2 levels but when i load level 2 the music from level 1 plays over the level 2 music

swift crag
#

I have prefabs for things like "a button that takes you to another menu screen" and "a way to edit a float"

ionic zephyr
rich adder
final kestrel
swift crag
#

Basically, I hand-author whatever I can't describe through code, and then automatically generate the rest

swift crag
#

they usually try to preview as much as possible on the client (including your movement) immediately

rich adder
#

lots of Client Side Prediction

swift crag
#

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

wheat lintel
#

i have a problem building my game, where can i get help, i'm a bit lost in this discord

wheat lintel
swift crag
polar acorn
# swift crag for a first person shooter?

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

swift crag
stuck palm
#

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

ionic zephyr
#

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?

polar acorn
modest dust
ionic zephyr
modest dust
#

Or, if it's a convoluted mess, just copy the slot data from one place to another

stuck palm
#

@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?

swift crag
#

first decide if you're actually doing rollback (:

#

if you aren't then none of this is really necessary

stuck palm
#

might start with delay based then make rollback when im more experienced

swift crag
#

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

stuck palm
#

ah yeah

#

honestly? might just do delay based for now

swift crag
#

this is where you enter notlikethis 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

stuck palm
swift crag
stuck palm
#

this is just straight up wrong, if you enter the article it says it doesnt use it lmao

swift crag
#

I think the problem is that there wasn't enough AI involved

stuck palm
#

true

swift crag
#

Duh. Just use AI for your networking

#

That'll fix it

#

RollbackGPT

raw token
# ionic zephyr I have an ItemSlot class and I created a slot prefab with that script. Those pre...

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.

ionic zephyr
candid burrow
#

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

late forum
elfin cedar
late forum
#

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;
    }
}


rich adder
late forum
#

I followed every step of the tutorial but the rotation is just... bad

swift crag
#

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

rich adder
#

or both

late forum
polar acorn
stuck palm
#
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?

rich adder
swift crag
#

So it runs befoe Start, yes (but after Awake)

late forum
late forum
swift crag
#

Follow the instructions exactly. !ide

eternal falconBOT
rich adder
summer stump
late forum
swift crag
#

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.

rich adder
#

yup simple fix, its in the guide

rich adder
#

this is atrocious, you should as a gamedev know how to take screenshots..

golden blade
#

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!");
        }
    }
}
polar acorn
golden blade
#

I have 2 scripts one where when both players collide one stops in its tracks

#

that works fine

#

this script should make it so

willow scroll
#

Does it mean that the method is called?

golden blade
#

the map camera turns off and the battle camera is turned on

#

I think so

willow scroll
swift crag
#

"i think so" does not cut it (:

golden blade
#

ok so i think so means

#

I dont know what u mean by method is called

#

ill google it

willow scroll
#

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

golden blade
#

say no more

willow scroll
#

Does it mean that you understand or I have to shut up?

golden blade
#

It means i understand

#

slang term

willow scroll
#

Oh, cool one

late forum
wooden socket
#

I want to show a score on a leaderboard scene but the text isnt showing

#

ive been trying for hours 😭

willow scroll
willow scroll
late forum
wooden socket
#

how do I show code in discord btw

#

this?

#

ok good

cosmic dagger
#

!code

eternal falconBOT
willow scroll
rich adder
#

rip

wooden socket
#

is this good?

rich adder
#

no

wooden socket
#

shoot lemme delete it

rich adder
#

also large code shoold be a link