#💻┃code-beginner

1 messages · Page 663 of 1

slender nymph
#

well you would serialize to and from the fields rather than the properties in that case

odd remnant
#

Probably an area I need to research specifically before getting too far into development. I just want to make sure I'm not setting myself up for failure.

slender nymph
#

serialization is the process of turning your data into a format that can be written to disk. that's what the SerializeField attribute does, it tells unity to write the value of the field to the yaml file associated with the gameobject

rich stratus
odd remnant
#

Ahh, I thought SerializeField only made that field accessible in the editor.

rich stratus
#

well he's just asking

slender nymph
odd remnant
#

Ok. That makes sense. Thanks so much for your help!

queen adder
#

InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.
UnityEngine.Internal.InputUnsafeUtility.GetAxis (System.String axisName) (at <8464a637132d4cf7b07958f4016932b9>:0)
UnityEngine.Input.GetAxis (System.String axisName) (at <8464a637132d4cf7b07958f4016932b9>:0)
EasyPeasyFirstPersonController.FirstPersonController.Update () (at Assets/EasyPeasyFirstPersonController/Scripts/FirstPersonController.cs:94)

#

help me plz broders

final forge
queen adder
#

I fixed it, I just had to set Input Handling to Input Manager (OLD) because I had it set to NEW.

orchid trout
#

What are possible reasons why VS fails to recognize a bunch/all unity concepts and is redlining them?
I tried closing and relaunching VS but it still redlines

rich adder
orchid trout
#

They don't

rich adder
#

oh so def VS issue.. have you tried regenerating project files?

orchid trout
#

Unity is able to compile, its only VS

#

I haven't, like deleting the Library folder or something else?

rich adder
#

Preferences -> External Tools -> Regen Project Files

#

if fails then yeah I would try Library deletion and regen that too

orchid trout
#

Gotcha. Ill try that now

#

I can't find preferences in any of the hotbar dropdowns

ashen arch
orchid trout
#

Oooh not in visual studio, gotcha. Yes that fixed it, thanks!

earnest wind
#

if i have a array of users which all have value of ID, how can i get the id's and put them in a list?

List<long> BlockedUsersIDs = new();
foreach(UserProfile value in BlockedUsersArray.value)
        {
            BlockedUsersIDs.Add(value.userId);
        }

Is this the best way?

cosmic dagger
earnest wind
ashen arch
earnest wind
#

and i cant do ToList

#

im getting values from the array itself

ashen arch
#

Okay

grand snow
cosmic dagger
#

True, I would set the capacity when creating the list . . .

earnest wind
#

check the lenght?

#

ohh like pre-load it

cosmic dagger
grand snow
#

do List<long> BlockedUsersIDs = new(BlockedUsersArray.Length);

#

then the list internal capacity is the correct size to begin

#

otherwise it may need to "expand" and it will be copied elsewhere in memory and be a waste

earnest wind
#

and it changes after load

grand snow
#

Ah well your example doesnt tell me that

#

dw about it then, you can give it a start capacity you think is smart

cosmic dagger
#

That way, the list will not create a new internal array and copy the current array to the newly enlarged list every time you exceed the capacity . . .

earnest wind
#

ig i can just do that right?

List<long> BlockedUsersIDs = new();
    async Task GetBlockedUsers()
    {
        ResultAnd<UserProfile[]> BlockedUsersArray = await ModIOUnityAsync.GetMutedUsers();
        if(BlockedUsersArray.result.Succeeded())
        {
            BlockedUsersIDs.Capacity = BlockedUsersArray.value.Length;
            foreach(UserProfile value in BlockedUsersArray.value)
            {
                BlockedUsersIDs.Add(value.userId);
            }
        }
        else
        {
            Debug.LogError("Cant get blocked users");
        }
    }
grand snow
#

you can actually set capacity later on a list with .Capacity

earnest wind
#

ah so like this

BlockedUsersIDs.Capacity = BlockedUsersArray.value.Length;
#

got it

#

thanks

grand snow
#

also try to migrate to UniTask or Awaitable instead of Task

earnest wind
#

void is fine

#

i dont have to wait for it

cosmic dagger
#

You can still set the capacity. Just use a reasonable number . . .

grand snow
true fox
#

Does anyone know/can guide me how to create a roguelike dungeon generation system inspired by Lethal Company?

odd remnant
#

Can someone help me think through what level of chopping up of Scripts I should be doing for a 3D First-Person Survival game? I have a FirstPersonController script that manages player movement, camera, and converts system input into actions like swinging a sword.

But then there's sprinting, which is based on a simple Stamina system. Have stamina? You can sprint. Out of stamina? You can't sprint. Stamina regenerates after a small delay when the player isn't sprinting. And all of these elements can be affected by in-game features.

maxStamina can be increased in various ways, items can affect the rate of stamina drain, etc. And a lot of these mechanics also apply to Hunger and Thirst. I've seen some tutorials that create a SurvivalManager that manages Hunger, Thirst, and Stamina (but not health) And Stamina feels like one of those features that straddles between a "survival element" and a "player movement" element.

#

What questions should I be asking myself to help determine whether Stamina should be inside of the SurvivalManager class, or inside of the FirstPersonController class?

rocky canyon
#

as a beginner i made singletons (gamemanagers playermanagers) that way i could for example call a method to add or remove stamina from anything in the game.. w/o needing to find creative ways to get the references i needed to give stamina, or give health, or this or that..

#

the more i designed the more i'd need to fine tune what i was doing, or maybe discovering something else entirely.. like interfaces, sending events, that kinda stuff

#

but i let it happen as i needed it to.. or else i never really retained that kinda information..
i knew things exist but not really when and where to use them.. (i still struggle with this, but dont we all lol)
but at first it was all singletons 💪 😈

rocky canyon
#
  • should it need to know about it?
  • should it manipulate it?
  • what is it's real job anyway?
odd remnant
#

Yeah I'm avoiding singletons for player elements because this will be a multiplayer game. But the S-principle actually helps a lot. The SurvivalManager's job is to manage a player character's state of survival - their Hunger, Thirst, Stamina, potentially Health (I think that makes sense), and probably any boons/debuffs on the player that affect these things.

#

And so the FirstPersonController is responsible specifically for player movement, but not for player "state". I'm gonna refactor the code to reference the SurvivalManager's values for Stamina.

verbal dome
#

Movement, camera, actions

verbal dome
#

Mainly because it's easier to organize and debug

#

Just my preference

odd remnant
#

Cool, thanks!

polar dust
#

a good rule of thumb is to keep things that "dont know about each other" separated.

Youd probably wouldnt ever need the camera to know when your character checks if theyre on the ground. As those two components will never "talk" to each other, and considering how very different they are, its practical to separate them.

A good reason for doing this, is that if your camera code works, and you accidentally break your movement code; the camera system shouldn't be at risk of also being broken

odd remnant
#

Though this is where "sprinting" throws me off. Because technically the First Person Controller needs to know IF the player can sprint.

#

But there will be many other interactions with the player's ability to Sprint - if the player has a debuff that prevents it, if the player is in a realtime cutscene that prevents running, if the player is out of stamina.

polar dust
#

well in that case, you could have a public bool in the movement class like isSprinting or canSprint, that way the camera is stil able to read what the state of the player is

odd remnant
#

Ok, that's what I currently have.

#

I have both actually. isSprinting tracks whether the player is actively sprinting, and canSprint is almost an "override" that can be toggled on-off to prevent sprinting in certain situations.

polar dust
#

id say try splitting it down into the individual components, dont alter any code right away, just move your code to the different components. The problem doesnt sound too hard to solve, and you may find that this kind of refactor could make it easier to spot the issue

odd remnant
#

Cool, thanks!

rocky canyon
mossy jasper
#

i used a offical unity tutorial and idk why its not working (I swear to god if its my IDE)

slender nymph
eternal falconBOT
grand snow
#

we need a new counter for this input error 😆

gilded oak
#

wanting to make a katamari-like game, i was gonna just go with a URP project but whats the difference between URP and the built in render pipeline?

#

planning on doing everything myself, however long that takes

rotund crown
#

in godot, i would have autoloads/singletons with signals, i could have scripts connect their own functions to those signals, then have other scripts call those signals to trigger them remotely
is there any way i can do something similar with unity events?

#

it seems like i'm almost there, but i cant figure out how to properly access a public class

rich adder
rotund crown
#

so a reference is always necessary?

rich adder
#

yea to access the instance

rotund crown
#

that means i'd have to add a serialize field and assign game manager to every single script then huh

rich adder
#

or use a Singleton pattern for game Manager so you can at least access the field/property/methods through that

rotund crown
#

that would work mhm, but how do singletons work in unity? from what i saw they're just public classes that delete any other instances of themselves you accidently create

final trellis
#

i want to add a walljump mechanic, i have a p good idea on how to make it work, when the player isnt grounded and presses the jump key, a raycast is cast infront of the player, and if it hits a wall, it takes the face normal

the specific part i dont know how to do is taking the specific face normal that the raycast hit

rich adder
rotund crown
#

yeah, in my case i'm only interested in the global accessibility trait of them

rich adder
#

the basic gist is making an Instance of that class Static so it can be easily accessed through that

rotund crown
#

ahh so it's a public static class and not just a public class

rich adder
#

not the class itself is static, but the Instance of it

#

the link I sent has example

rotund crown
#

mhm i'll go have a peep at it

#

hehe we love this website here

rich adder
#

yeah the domain is pretty cool

#

was done by a moderator here

rotund crown
#

yay seems to be working now

#

now next step, how can i pass on a variable through a unity event?
ie add a function with an argument as a listener for a unity event
then have another script call that unity event, and attach a variable

#

is that what UnityEvent<> is for?

rich adder
# rotund crown is that what UnityEvent<> is for?

yes iirc only supports specific types? been a while... to me UnityEvent is mainly useful if you plan on adding subscribers through inspector, otherwise I would suggest go with Action or other Delegate

rotund crown
#

yeah it seems like the purpose of unity events is for inspector assignment

#

i skimmed thru a lil bit of info about delegates, sounds like unityevents are delegates but with inspector integration added on

rich adder
#

basically yea

rotund crown
#

for prototyping and testing, i want to slap artificial delays into my script (as placeholder until animations are ready)
is this a good way to do it?

#

just have every functiont hat will have delays be an async, then add in these awaits?

rich adder
#

in Unity generally recommended to use Awaitable or coroutines .

iron otter
#

VS Code version: 1.100.2
C# Dev Kit version: 1.19.63
C# version: 2.76.27
.NET SDK version: 8.0.405
C# Dev Kit logs: https://basedbin.fly.dev/p/e9lJem.txt (its not a link to download its pastebin)

help my C# dev kit is not recognizing my .editorconfig but when I use dotnet format it does recognize it

iron otter
rotund crown
#

hm, i'm getting a null reference exception when referencing this static class

#

does it need to be declared in this funky way?

rotund crown
iron otter
rich adder
rotund crown
#

well the error happens before i can get to the part of the logic that invokes them
so no

rich adder
#

why is it static UnityEvent anyway ?

rotund crown
rich adder
# rotund crown

yes because you made game manager a static class instead of a component so most likely the UnityEvent isn't initialized and you're trying to access a method on it

rotund crown
#

ah i see, so would swapping to delegates solve it?

rich adder
#

opt for Action or other delegate type

#

public static event Action<int> tileDrop etc.

rotund crown
#

so now the syntax is like Gamemanager.tileDrop += functionName
then just call Gamemanager.tileDrop

rich adder
rotund crown
#

do you .Invoke action events?

#

hmmnm

rich adder
rotund crown
rich adder
# rotund crown

did you actually save changes when you switched tileDrop to Action ?

frigid sequoia
#

What would be the proper channel to ask for the configuration of a line renderer? vfx and particles??

rich adder
#

also for ambiguous reference on Random you can assign UnityEngine namespace to it
using Random = UnityEngine.Random

rotund crown
#

hmm, this ide is a bit odd and seems to autosave whenever it can, but it works properly for this syntax so i think it's properly saved

rich adder
#

weird..are you using rider btw ?

rotund crown
#

mhm

rich adder
rotund crown
#

it's not just an ide bug it seems

#

so its saying only GameManager itself can invoke it?

rich adder
rotund crown
#

mhm

#

can event actions not do that?

#

is there a form of delegate that can? or do i just need to have a unique public function for each event action

rich adder
rotund crown
#

oef that's gonna be alot of functions

rich adder
rotund crown
#

yeah i guess in practice it just makes it 2 lin es of code instead of 1

#

mm, so using coroutines doesnt delay the function int he way i hoped it would huh

#

it will simply call insert delay and print wait every frame

rich adder
rotund crown
#

oh okay

rich adder
#

but there are also other implications there, mainly the whole encapsulation thing and all

rotund crown
rich adder
#

also you're missing StartCoroutine()

#

so anything delayed goes in the IEnumerator itself under the yeild

#

btw unity has some functions already as IEnumerator such as start

#

IEnumerator Start(){
//yield wait
//do something after delay, such as calling another function

rotund crown
#

mhm, which means i have to have a separate ienumerator with logic inside of it for every delay i want to have, which is inconvenient
is there a more convenient way to insert artificial delays? one that works midway through a function?

#

wait should i just have my main function be an ienumerator and use yield return new WaitForSeconds()

rich adder
#

Awaitable is also an option

rotund crown
#

hmm, i'm trying to check if it's working by having it print, but instead the console is getting spammed with this

#

is it something i need to worry about or is it just unity jank?

rich adder
#

hard to say could be bad code you wrote somewhere or editor bug

#

try restarting unity

gilded oak
#

oh my god im learning of so much very quickly, dont know if too quickly, started with looking up what a string is, now im learning what access modifiers are

rich adder
#

can be bad if you're not following structured path though

#

access modifiers are the very basics so yes its important stuff

gilded oak
#

ah im at least glad im learning the stuff i should be early then

#

for now its mostly just escaping my mind but im writing stuff i learn into a powerpoint doc

rich adder
#

imo the microsoft website is one of the best places to learn c# basics

gilded oak
#

reading can be hard sometimes ngl, so what im basically just doing is para phrasing everything i learn into powerpoint

#

not really sure if i got these right so apologies if things arent technically correct

#

time.deltatime confused me, still dont fully get it

rich adder
#

so rather than moving an object based on framerate you're moving it based on seconds

rotund crown
gilded oak
rich adder
gray anchor
#

Hello there! Sorry to interject but I have an issue I was hoping someone experienced could help me with. I am following a YouTube tutorial on how to create a Platformer, and I have been doing pretty good! But I just hit a spot where it gave me this error:
"UnassignedReferenceException: The variable animator of PlayerMovement has not been assigned."

And well, I don't know if it is something I did wrong/missed in the tutorial, or if it is because the tutorial video is in an old version of unity, so maybe there is an extra component I am missing. Any insight would be greatly appreciated! Thanks for reading.

rich adder
gray anchor
rotund crown
#

why isnt this looping? (only prints once)

rich adder
#

you need StartCoroutine

brave robin
rich adder
#

also if you need to repeat itself you should use a while(true) loop

brave robin
#

In fact, recursively executing that way is a bad idea in a coroutine.

rich adder
#

yeah best use a regular loop instead of recursive calls
more of a chance shit going bad

gray anchor
brave robin
rotund crown
rich adder
#

this is just a script file

#

Instance its when you put the script on a gameobject

#

it becomes a component

brave robin
rotund crown
gray anchor
#

Ahhh, so up here?

rich adder
#

hence the error

#

it doesnt know Which exact Animator you want to do stuff on

gray anchor
#

Ahhh I see. I think I get it now, thank you.

brave robin
rich adder
rotund crown
#

well it's not gonna loop, i'm just trying to figure out how to make it wait

rich adder
rotund crown
#

mhm i know it's bad practice

#

but uh how do i make it actually wait for the 1 second

rich adder
#

its used in very specific times

rich adder
ashen arch
#

StartCoroutine("Start")

rich adder
#

why in the hell would you ever use string for calling function

rotund crown
#

is it just terminating the loop coz the engine knows that's bad practice?

rich adder
ashen arch
#

then stop recommending unity docs to people

rich adder
#

with common sense one knows to use a Type safe method call

rotund crown
#

oh weird, yeah it does seem to work, i guess unity was just exploding coz it hates loop

rotund crown
#

recursion?

rich adder
#

recursive functions are not exactly loops

#

well maybe its a technicality in naming, but loops generally I would associate iterating

#

recursion consume lot more memory cause of the stack

rich adder
brave robin
#
while(true)
{
   yield return new WaitForSeconds(1);
   Debug.Log("I LOOPED");
}

That's a loop.

#

Damn, beat me to it 🙂

rich adder
#

nice

brave robin
#

Ideally you'd create and cache the WaitForSecons outside of the loop and just reuse it, rather than make a new one every loop, but that's for another lesson 😄

rich adder
#

true

#

or do what i do and skip creating a new object at all

 while(true)
        {
            float t = 0;
            while(t < 1) // ideally you don't make 1 a "magic number"
            {
                t+= Time.deltaTime;
                yield return null;
            }
            print("print after 1 second forever");
        }```
fair shore
#

I have a checkerboard marked in x and y coordinates, how can i access the first row or the first column of the checkerboard.

brave robin
#

I also do the timer loop, but mainly because I often want to be able to exit the loop before the timer runs out if other conditions are met.

rich adder
#

or are they separate cells

fair shore
rich adder
#

how are you drawing them on then

#

so are you using 2D array ?

fair shore
rich adder
#

var cell = myGrid[x,y]

frigid sequoia
#

Shouldn't these be the same?

#

Am I dumb?

north kiln
#

rendering layers are not sorting layers

frigid sequoia
#

Shouldn't I be matching the sorting layers and rendering layer mask to tell which masks affects each sprite?

north kiln
#

I'm unfamiliar with how sprite masks work, I'm sure the documentation says

#

This is a programming channel

frigid sequoia
#

Where do I ask that, on 2D tools?

north kiln
#

Sure

rotund crown
#

why is this update funcitno not running?

rich adder
#

what does yellow underline mean on Rider anyway? I'm guessing it doesn't like camelCase methods

rotund crown
#

mhm

#

just wanted to check that i'm not crazy and it's spelled right

#

ah nevermind

#

hm, how do i tell it not to expect a return value?

brave robin
#

You have to use StartCoroutine to start a coroutine

rich adder
rotund crown
#

ah

rich adder
#

also calling StartCoroutine every frame will create a new coroutine each frame btw

#

probably not something you want

rotund crown
#

hm and they dont automatically terminate themselves?

rich adder
#

nope

rotund crown
#

oh annoying, i was hoping to just use them like regular functions so i can insert arbitrary delay

rich adder
#

well they do after its done but Starting one wont end another , thats what I meant lol

rotund crown
#

oh well that's fine then

brave robin
#

Coroutines will automatically become garbage in memory if they don't loop, it's unwise to do them every frame due to the memory overhead and eventual garbage that needs to be collected

rotund crown
#

even after they finish?

brave robin
#

Its allocating space in memory for them, every single one

rotund crown
#

oh well i guess it's just an if() clause, so i can just have that in update instead of in the coroutine

rich adder
#

if GC has to collect a lot within a frame it could be issue in performance

rich adder
rotund crown
#

so if coroutineVar == null, start coroutine, else pass?

rich adder
#
Coroutine myRoutine;
void Method(){
if(myRoutine == null)
myRoutine = StartCoroutine (TheRoutine());```

```cs
IEnumerator TheRoutine(){
//do stuff
myRoutine = null```
brave robin
#

Why do you need a coroutine in this case? What operation is it doing?

rich adder
#

iirc they want a function that can have delays between stuff

rotund crown
#

yup

#

how do i toggle this li'l checkmark enabled/disabled property via script?

brave robin
rich adder
#

that one is SetActive
[SerializeField] GameObject theGameObject
theGameObject.SetActive(bool)

brave robin
#

Oh wait, yes, that's not a Text component

rotund crown
#

o oka

#

seems to have an enabled property, but not a setactive function

rich adder
#

so diceLabel.gameObject.SetActive

#

btw components have .enabled when they have any of these method implemented

gilded oak
#

random question, so the top vector3 line works but the 2nd one doesnt, why is that? it seems like the same code but certain parts are not highlighting despite it being the same

rocky canyon
#

input is not the same as Input btw

gilded oak
#

oh

#

wait

rich adder
gilded oak
#

yep just noticed

#

🤦

#

cant believe i didnt realise the i in input was different, that was making everything not work

#

my bad

#

thanks

rich adder
#

yes c# like many languages is case sensitive

gilded oak
#

yep lol, just didnt notice that i was not capatilised :/

#

i used python in high school but its been years since that im basically relearning

rocky canyon
#

c# will set u straight 😄

gilded oak
#

it sure will 😅

rocky canyon
#

python just dnt care

#

all willy nilly

naive pawn
rich adder
#

SQL is pretty big lol

naive pawn
#

ah true, though that isn't a programming language

#

i guess asm lol

#

though it also isn't one 🙃

rocky canyon
#

BASIC is pretty badass

rich adder
#

older ones too ig like Cobol or Fortran

naive pawn
#

ah im not familiar with those at all, cool to know

final trellis
#

im going insane

timber tide
#

Update isn't the easiest to debug, but I suggest start debugging by the final velocity value and then going down the list

wintry quarry
#

That's guaranteeing you'll have different jump heights for different framerates

final trellis
#

riiiggght, makes sense since its not every frame

wintry quarry
#

A lesser but also real issue here is that you cannot use Update for consistent physics

#

There's a really good reason the physics engine uses a fixed time step

#

You can't get a consistent simulation without one.

#

deltaTime is not sufficient to correct for second order effects like acceleration

#

It can only accurately fix first order changes over time like a constant velocity

timber tide
#

But CC doesnt work in fixed, no?

#

Not a fan of that controller anyway

final trellis
#

i think it does, but yeag ima move the velocity related stuff to FixedUpdate

timber tide
#

I mean it does make sense that it can work in fixedupdate, but the visuals would need to be interpolated

final trellis
#

i dont have to use the .Move() function in fixed update if i only do the velocity decay and gravity there

gilded oak
#

got something super early, mostly just followed a tutorial but was also trying to learn what everything meant at the same time

#

only thing im not happy about is that when rolling over an object, the ball struggles to roll, so that will be the first thing i figure out myself without a tutorial on youtube

#

this is the code ive done so far

timber tide
#

You could just remove the collision from the cubes* and just have them stick to it, or if it's supposed to affect the geometry collider yeah that's not the easiest

rich adder
#

potentially increase just size of the sphere collider radius that matches the prop

gilded oak
#

yeah its an odd one, cause in katamari the objects you roll over does effect how the katamari moves, but it doesnt make it impossible to roll over

#

ooh that could work

#

ill figure that one out haha

rich adder
#

btw no need for Time.fixedDelta time in AddForce its already moving on fixed time

gilded oak
#

as the sphere would get bigger i would need the collider to basically inscrease in size too

gilded oak
rich adder
#

they probably wrote it without understanding how it fully works

gilded oak
#

maybe maybe

#

at least glad i got a foundation i guess. as long as i can build off it then im happy

#

i have found a solution, just made the collision boxes smaller on the cubes. instead of a size of 1, ive made the collision boxes 0.2

#

unsure yet if i would get away with that for any assets i make but its at least viable for now

final trellis
#

im not using a physics based character controller bc i feel like itll introduce too many variables i dont want to deal with, and all i really need is decaying speeds ( gravity and "knockback" )

#

( "knockback" only being a thing for walljumping )

shut swallow
#

It calculates the time between two frames

#

It's always a good move to put movement in fixedupdate

final trellis
keen dew
#

CC should be used in Update

shut swallow
#

I mean physics events

#

Depends on how you treat your movement

#

I personally put all my movement code in FixedUpdate because it can guarantee consistent movement

shut swallow
#

But my suggestion is to always put physics in fixedupdate

keen dew
#

Great suggestion, but as they said, they're not using physics-based movement

final trellis
#

i need the tiniest bit of physics

keen dew
#

"physics" in this context means the physics engine specifically

cosmic dagger
#

They're talking about the using the physics engine . . .

final trellis
cosmic dagger
#

If you're not moving using the physics engine, you can apply your own gravity in Update. Obviously, a custom solution . . .

shut swallow
#

You can implement gravity by apply force in air by applying gravity*Time.deltaTime on your velocity

#

I think fixed delta time and delta time makes no difference in terms on how it feels to play

#

Unless it’s like extremely low frames

timber tide
#

I mean I don't exactly know the differences of how acceleration behaves between doing it in update or fixed, but a large reason that fixed is useful is that you're not doing expensive queries dependent on your frame rate

#

It's more performant to predict or take some sample and interpolate that information than grabbing it 200-300 times a second

shut swallow
#

That depends on what that process is, I mean you can just use a coroutine for async for functions like that if you want to run in parallel

timber tide
#

I assume CC isn't doing these expensive operations on a frame basis, but rather accumulating those values then doing it at a step further in time which is why you do populate these buffers in update

gilded oak
#

i was trying to write code to lock my cursor to the game screen and make it invisible but it doesnt work. do i need to make a new script for this code or am i able to put it in my ballcontroller script?

#

this is the code btw

keen dew
#

And where do you call that function?

gilded oak
#

if im being honest im unsure, still learning and was looking up a youtube video

#

just started today

ivory bobcat
#

You need to call the function with one of Unity's built-in callback functions (messages)

#

Awake, Start, in Update somewhere given some condition etc

gilded oak
#

ohhh alright 2 secs

ivory bobcat
#

For example cs private void Start => cursor();

gilded oak
#

like this?

#

swear im not trolling btw if im wrong

ivory bobcat
#

Case sensitive

gilded oak
#

oh yea, ive got start somewhere else in my script

#

would i need to put the code ive got in that screenshot im assuming underneath the other start ive got

#

just noticed yea

#

this is the other start

ivory bobcat
#

Those lines of code won't automatically run. You'll need to either insert those lines of code into some function that is called by Unity or call your non-Unity function manually

gilded oak
#

ah alright, so ive at least gotten the case sensitivity gone, moved the code

#

there we go, the code is working now

#

we might need a new text channel...

#

call it code-babies...

#

and put just me in it..

#

anyways, ill send my progress so far

#

probably gonna take a break and soak in what ive maybe learned today

#

actually somewhat proud tho, despite me using youtube tutorials

ivory bobcat
gilded oak
#

oh right, ill post there, thanks

gilded oak
#

i have made my post 🫡

eager cypress
#

c# is really similiar to java

#

whys a float called a double though

eager cypress
#

ohh

#

thanks

keen dew
#

It's exactly the same in Java

eager cypress
#

really?

main current
#

can anyone help with this? whenever i use a buffer jump it is always a full jump and i cant control it with variable jump height

#

i used brackeys movement script

#

the 1st image is in update and second is in a function

keen dew
#

The last line sets jumpBufferCounter to 0 so it'll only run once regardless of how big the counter value is

main current
#

how do i make buffered jumps vary with variable jump height?

hidden marten
#

im using this script for shooting with a bullet. the bullet is going in a completely different direction. i even check with a debug drawray, but the bullet is going in a completely different direction from the debug ray. what am i doing wrong?

#

the script is in the gun object btw

median hatch
#

i assume when you pass by the cubes they turn into children of the sphere?

#

sounds like a fun idea

median hatch
#

in this case youre just instantiating with whatever rotation the bullet has

hidden marten
median hatch
#

what?

#

if your gun is pointing forward then your bullet should also point that way

hidden marten
# median hatch what?

the rotation of the bullet is zero.. im adding force to the bullet based on the direction of my gun right, so how does the rotation of bullet matter

median hatch
#

the forward point of the bullet needs to be the same of the gun

#

otherwise the bullet just goes towards another direction

#

you can make a bulletSpawn in front of the gun for clarity

#

then when instantiating the bullet you set its rotation to the same of bulletSpawn

#
        GameObject bullet = Instantiate(playerController.drinkEquipped.bulletEffect, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
#

something like this

hidden marten
median hatch
#

i wouldnt put the rotation to the gun itself, since you might have more than one gun with different shapes

#

but to a gameObject that is in front of the muzzle of the gun

gilded oak
#

once ive got these down ill start with figuring out unique stuff i can make for the game

median hatch
#

make it subtle like 0.1 or something

gilded oak
#

or something i seen online, could add on the size of whatevers getting picked up to the size of the sphere maybe?

median hatch
#

yea or that depends on what you want

#

for the biggest object falling i'd store their scale in a script

#

then when picking it up you send that data to a list in a general script attached to the sphere

gilded oak
#

my brain just exploded

#

lol

median hatch
#

um problema de cada vez

gilded oak
#

wait

median hatch
#

for now just try to make the sphere bigger

gilded oak
median hatch
#

sim

#

only english channel tho

gilded oak
#

yooo same, although i suck at speaking and writing

#

yea npnp

median hatch
#

PORTUGAL CARALHO

shadow briar
#

Hi everyone, i was wondering if anyone could help me try to understanding how to use composition a bit more modular and in conjunction with each other.
Because currently while i get the basic idea, its to make it easy to reuse stuff but actually using it in an effective and different manner is where im getting a bit wobblily.

Like for example i made a health component, since im gonna have wildlife and humans in my project.
Put it on these different entities and they have Health stuff - events or otherwise, no need to rewrite the code in other scripts.

So if i want a human to grunt in pain - i would think we make a Human script, that has a Method called MakeGruntNoise() and it subscribes to the TakeDMG() from the Health Comp.
Like is that the general idea or have i crossed some wires - other ways to do it?

hidden marten
median hatch
hidden marten
#

there is no bullet code

#

yet

median hatch
#

show me the gun component

hidden marten
median hatch
hidden marten
median hatch
#

and that script is attached to the enemy?

hidden marten
median hatch
#

thats why

#

transform.position, transform.rotation are grabbing the transform of the enemy

#

not the gun

hidden marten
hidden marten
#

red color

sour fulcrum
#

can you show the debug ray code aswell

hidden marten
#

that's transform.forward and thats the direction im putting force in

hidden marten
median hatch
#

well on transform.position set it to transform.forward then

hidden marten
median hatch
#

no

#

on the bullet

#

on the Instantiate(...)

hidden marten
#

OOOOH SHIT

#

how did i miss that 😭

#

thanks a lot!!!

median hatch
#

have fun man

median hatch
#

if you have multiple things that can get damaged i'd make an interface tho

hidden marten
#

the parameter is position how is transform.forward gonna work

honest mural
#

hi, i wanna make a question game with drag and drop system and after the player put the answer a check mark to show if it s right or a x if it s wrong but i can t rlly know how to make the script for that can someone help?

median hatch
#

wasnt it working

hidden marten
median hatch
#

put it where you want it to shoot from

#

then instantiate there

hidden marten
#

i checked fr now haha

#

thanks a lot!!!

pliant abyss
#

Keeping my platformer character grounded

warped wolf
#

hello guys, i'm new with code cause i'm an artist and start to learn shaderlab, anything should i need to notice?

timber tide
#

GLSL/HLSL for the most part

warped wolf
#

CG outdate?

brave compass
#

CG can still be used, but it's just a compatibility layer on top of HLSL and considered legacy.

#

It's used by the legacy render pipeline. URP and HDRP use HLSL.

timber tide
#

You can get away with a lot of basic shaders with CG

#

but if you want to do something lit, you'll need to know Unity's macro lingo

warped wolf
#

what's that?

timber tide
warped wolf
#

thank you ^^

#

do i need to know C++ or C# or some code language else?

naive pawn
#

c# for unity, but shaders are a separate thing

warped wolf
#

i see, thanks

hidden bluff
#

hey im currently running into the problem my charcater is running but as soon as the stamina runs out he keep running unless i let go of shift and press it again then it stops running

rich adder
hidden bluff
#
public void PlayerSprint()
{
    {
        if (isRunning && Stamina > 0)
        {
            Stamina = Mathf.Clamp(Stamina - (StaminaDecreasePerFrame * Time.deltaTime), 0.0f, MaxStamina);
            StaminaRegenTimer = 0.0f;
            sprintSpeed = 2;
        }
        else if (Stamina < MaxStamina)
        {
            if (StaminaRegenTimer >= StaminaTimeToRegen)
                Stamina = Mathf.Clamp(Stamina + (StaminaIncreasePerFrame * Time.deltaTime), 0.0f, MaxStamina);
            else
                StaminaRegenTimer += Time.deltaTime;
        }
    }
}
hidden bluff
tribal fulcrum
#

hello guys, can anyone help with triggering point lights?

#

i have a plinko game, and i want a point light to trigger on to the peg to make it glow

rich adder
#

incomplete information

rich adder
hidden bluff
#
public void OnSprint(InputAction.CallbackContext context)
{
    if (context.performed)
    {
        isRunning = true;
        PlayerSprint();
        //sprintSpeed = 2;
    }
    else
    {
        isRunning = false;
        sprintSpeed = 1;
    }

}

polar acorn
hidden bluff
#

it is

polar acorn
#

this isn't update, this is a button callback function

polar acorn
hidden bluff
#
private void Update()
{
    PlayerLook();
    PlayerMove();
    PlayerSprint();
    //HoldItem();
}
wintry quarry
#

ok so why is it ALSO in the input callback

tribal fulcrum
rich adder
polar acorn
eternal falconBOT
wintry quarry
#

you should explicitly check if (context.canceled) to do the = false part

#

and depending on how you configured your input action - performed might not even happen right away

tribal fulcrum
rich adder
hidden bluff
wintry quarry
rich adder
#

yes reference the actual component you want with a serialized field

tribal fulcrum
#

thanks im still very new to unity so i have questions

rich adder
#

so all together could be something like this for script on the peg, if its 2d game use 2D variant for OnCollision

    [SerializeField] private Light myLight;
    [SerializeField] private float lightOnTime = 0.15f;
    IEnumerator OnCollisionEnter(Collision collision)
    {
        myLight.enabled = true;
        yield return new WaitForSeconds(lightOnTime);
        myLight.enabled = false;
    }
tribal fulcrum
hidden bluff
lean pelican
#

How do I rotate a Vector2 around the z-axis by an angle? I tried manually using a rotation matrix, but it's going all over the place. I also found Quaternion.AngleAxis, but how do I apply a Quaternion to a Vector?

slender nymph
#

multiply Quaternion * Vector3 returns the rotated Vector3, then just convert back to Vector2 (which just drops the Z axis)

wintry quarry
#

Simple code example (rotate 50 degrees clockwise around the z axis):

Vector2 rotatedVec = Quaternion.Euler(0, 0, 50) * myVector;```
lean pelican
#

I also figured out what my original issue was. Vector2.Angle (and Unity/Transform in general) work on degrees, but Mathf Sine/Cosine want the angle in radians instead, so I was getting nonsense results.

wintry quarry
#

true

odd remnant
#

Hey everyone, got a question about prefabs. I have three wheels on my UI that represent player hunger, thirst, and stamina. All three wheels should work exactly the same - the StaminaRing_Visual has an Image component with the Image Type "Filled", and its Fill Amount is tied to the class SurvivalManager's StaminaPercent property. Simple enough.

Each of these work the same way, and so I have the sense that they should be three prefab variants of a base prefab of "SurvivalMeter" or "SurvivalWheel". Does that sound right in theory?

timber tide
#

Variants are nice for things like enemies where you may find yourself with a hefty amount of variations, but otherwise it's not a requirement

wintry quarry
#

or even just a single prefab and a script that sets the sprite in OnEnable

naive pawn
#

why not just have them as instances of the prefab and override the sprite and perhaps the names

wintry quarry
#

or that yes

timber tide
#

A good question about variants is do you find yourself in a situation that you want to modify all variants by changing the main prefab

odd remnant
timber tide
#

Just making instances like chris mentioned is probably the idea here

naive pawn
#

same for prefab variants

odd remnant
wintry quarry
#

That's a very typical approach

#

or in a separate Init function

#

depending on how you populate these things in the scene

naive pawn
#

you can think of it in layers
an instantiated prefab would be a gameobject with that prefab as its "parent"
a prefab variant would itself have the prefab as its "parent", but it can also be a gameobject's "parent"

odd remnant
#

And then from a "best practice" perspective, should I create a SEPARATE script for the Ring_Visual object to determine the FillAmount and draw the ring with that percent value? Or would I keep this logic at the top-level StaminaRing object?

naive pawn
#

i'd just have 3 instances of the prefab and override the image in the inspector

naive pawn
#

then you could have the "management" script that controls said values accept Images for each meter, so that "management" script would be able to set the fillAmount

timber tide
#

Good way to think of variants is you've an enemy prefab but you split it down the line into different types which include subtypes, so for instance you got Elves -> Deep Elves, Dark Elves, Orcs -> Green Orcs, Blue Orcs, and you want to apply a component of knockback to only the orc sub set

odd remnant
# naive pawn then you could have the "management" script that controls said values accept `Im...

At first I was going to disagree with the approach, because I feel like the Ring should be responsible for drawing itself, rather than some management script (in this case probably the SurvivalManager script) but when turning this into a prefab, I lose the ability for the ring to know...what it is. Is it a Hunger Ring, a Thirst Ring, a Stamina Ring? And so which variable should it set itself based on.

#

But maybe I'm not aware of some way to get this to work (without using hard-coded enums/strings/case statements)

night mural
#

it's kind of up to you which you feel works best for your workflow

#

the thing you're discovering though, that it's very helpful in games for them to be able to reason about themselves, is accurate and why a lot of games trend towards being very data driven instead of collections of self contained objects

night mural
# odd remnant

that's pretty abstract advice, so more concretely I would say that if you are splitting your visuals out like this, you probably do probably want to 'hydrate them' in some top-down way from a manager like was suggested, rather than having them reference the manager and query their data

odd remnant
#

I'm not sure I 100% follow. I understand the distinction between "Displaying your game" and "Your game logic". The Ring doesn't understand how/why the percentage is set. It just displays the percentage.

But where I'm not understanding is the philosophical difference between "The Ring should go GET the percentage" vs. "The SurvivalManager should PUSH the percentage to the ring"

night mural
#

in what you showed, the manager isn't actually managing

odd remnant
#

I think this comes from a place where, say I brought on a new developer - and that developer goes into the UI and clicks on the Ring and sees "The Ring has a Fill Amount that's being set somewhere"

There's no easy way to figure out WHERE that value is being set how that value is being set.

night mural
#

I would say that mostly it doesn't really matter, except that it is simpler to reason about/manage 'these few top level things which control everything else' compared to 'everything querying anything it wants everywhere'

night mural
#

that person will only be interacting with your code for very short periods of time and if the thing they have to learn is 'it's set by one of the dozen managers', that seems pretty low-lift to me

#

what I do is segment things out in a way that feels reasonable to me

rocky canyon
#

Alt + F combined with Find Referenes, etc is plenty enough to find where and how the FillAmount is being set

night mural
#

so I have 'views' which are responsible for querying data and then pushing it down into the components, which are mostly dumb and just display data

#

the views are contextual and understand the game, the individual components just display what they're told

rocky canyon
#

waitt.. are u the guy yesterday that was asking bout where and how to split ur code up?

odd remnant
#

I might have been Spawn, yeah.

#

Which it's been split in a way that now works really nicely.

rocky canyon
#

very gucci 👍

#

if ur familiar with XML and code Summaries you can also document ur code along the way.. it really helps people thta may be lookin in on ur code

#

basically adds those tooltips and variable descriptions when u hover them

odd remnant
rocky canyon
#

and inside intellisense when ur scoping methods

night mural
#

when TestACloserThanB tests that A is closer than B mindblown

rocky canyon
#

and values

odd remnant
#

But in an object with no script at all? In the Inspector?

rocky canyon
rocky canyon
#

like [ToolTip("Blabla")]

night mural
rocky canyon
#

and that ^

night mural
#

these things are only problems if you're inconsistent and...just never do that! 😛

odd remnant
#

Lol

rocky canyon
odd remnant
#

This is in the effort of consistency. So I'm with you on that. 😉

rocky canyon
#

ya, when is too much too much?

#

if you can.. type ur code out in a way thats as readible as possible

#

without any fancy attribs or tags

night mural
#

I think that if your unity scene is mostly stuff that's getting hydrated and you are consistent about where from, that's much simpler to convey than a lot of 'architectures' you'll come across

#

this is a lot of the philosophy behind ECS

#

where are components changed from? systems, and it's simple enough to see which systems query which components

odd remnant
#

So, I feel like there are two trains of thought here:

A. The SurvivalManager should manage (and set) the fill-amount for visual objects on the screen. It manages both the game logic AND is responsible for distributing values to members around the UI and game. I don't know if I fully agree with this method, but it's one method.

B. The UI objects themselves have logic that reference the SurvivalManager and query it for the state of the player character. They set their own values.

I know how to do method A. SurvivalManager keeps the rings as object references, and directly sets their Image.FillAmount value to the percentage values of HungerPercent, ThirstPercent, StaminaPercent.

But (and I might not use it, but I want to understand how it would be done) how could I accomplish method B? Particularly if the rings were part of a prefab.

rocky canyon
#

B. gives me eww vibes

wintry quarry
#

I vote C

rocky canyon
#

me too! 💪

odd remnant
#

Actually I'm amenable to C for sure. Though this value changes literally every frame anyway.

rocky canyon
#

also eww

#

😈 lol

odd remnant
#

Really? Stamina changing every frame is ew?

rocky canyon
#

well if its being used every frame nah

#

but if its updating for no reason yes

night mural
odd remnant
rocky canyon
#

like say ur standing still..

#

@ idle..

rocky canyon
#

it shuldnt be doing anything

odd remnant
#

The value doesn't change, right.

rocky canyon
#

only when its being added to.. or subtracted from

#

then it -> should get updated

#

thats part of the pattern they mentioned ^ when it gets changed an event goes out

#

ui or ui manager sees that event.. and oh.. it changed? well ill update

night mural
#

the only thing with events is you have to deal with decentralized sequencing, which doesn't matter a all for a lot of things but can be very annoying for stuff where it does a lot

odd remnant
night mural
#

if your game tends to be made up of specific triggered sequences rather than being more of a simulation, it can be nice to just control the meat of that directly instead of mucking about with events

rocky canyon
night mural
rocky canyon
#

my UI manager has refrences to all the UI it needs..

night mural
#

or subscribe, i guess

rocky canyon
#

then i tell the UI manager to change values when possible

wintry quarry
rocky canyon
#

always dozens of ways to do things.. 😄 mines a little lower on the totem pole

#

prakkus and praetor are way more skilled than i

odd remnant
#

So SurvivalManager has Properties A, B, C, with Events A, B, C that fire when those property values change. (I'm generalizing terms here for the sake of brevity and understanding)

I have three instances of Prefab "Ring", who needs to subscribe to A, B, or C. How does each object instance specifically subscribe to Event A, B, or C?

night mural
#

it's funny because you're thinking very data-driven which I love and would embrace, but it's not where most people are when they pop in here or in line with most of the common advice you'll receive

#

often, a 'change' to your gamestate is more than just one piece of data changing (one property, which would fire an event, in your example)

rocky canyon
#

ya, fr.. im out my wheel house

#

lol

night mural
#

so it doesn't really make sense to have events for 'this piece of data changed' (not actually true, I do this, but I don't use them that much'

#

more often what you want is to represent your game in terms of what actually happens

#

if you go do webdev they'll talk about how everyone is all excited about domain driven design now

#

but really it's just 'model your game in terms of what it is'

#

so you would decide what things happen in your game and those would be your events

rocky canyon
#

lmao!!! my VSCode AI extension just gave me a pat on the back 😐

#

not sure how i feel about that

odd remnant
#

(Yeah, I worked in FinTech consulting for several years, with a bit of DB development, scripting, app dev, etc. all thrown in there) The video game domain has always twisted traditional programming fundamentals on its head a bit, because of its more...real-time nature.

rocky canyon
#

speakin of.. anyone using VSCode? Codiuem seems to have gotten a new Brand..

night mural
rocky canyon
#

Windsurf

odd remnant
#

Hahaha, I'm ready to feel the same Prakkus.

night mural
#

if you are comfortable with it, model your game as a relational DB with CRUD events and you can do a lot with that

rocky canyon
night mural
#

update your ui every frame because it doesn't matter, or optimize places where it does if you want to

#

and just have stuff that gets queried and updated

#

this is basically waht ECS is too, just with a different data structure (and since it's your gamestate, you can use whwatever structures you want, mix and match them, go crazy)

odd remnant
#

So to wrap this up then, I'm actually thinking of creating a UIManager that sits between UI elements and the SurvivalManager and communicates for them.

#

The UI manager will keep references of each ring, and pass them values from the SurvivalManager either when they change, or simply every frame (as their values are typically changing every frame anyway)

lean pelican
#

Is there any clever/more efficient way to check if an object in 2D is outside the (fixed) screen bounds? Or do I just need to keep manually checking its position? (If it matters, it's for a moving object that's supposed to despawn once it goes offscreen, and will only show up in small numbers at a time)

rocky canyon
rocky canyon
wintry quarry
odd remnant
#

And - thanks everyone. The discussion was helpful (if only a bit long-winded to get to the practical answer 😉 ) I appreciate the patience and the desire to help others out here.

rocky canyon
odd remnant
#

If I've learned anything during my time on the internet, it's only worth investing time in the people who are truly trying to learn/discuss/grow in good faith.

rocky canyon
#

we dont need any more Gorrila Tag coders

#

we need more like you 🫵

#

lmao

rocky canyon
odd remnant
#

BTW, I wanted to clarify something about the C# naming conventions. I think you sent me this yesterday, Spawn? https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/identifier-names

Am I understanding right when it says "Use PascalCase for constant names, both fields and local constants" that if I defined a reference to a class called SurvivalManager in my UIManager, that I'd called it "SurvivalManager"?

rocky canyon
#

and i totally agree.. as do most of us thats dedicating our time to help out..
if ur not "trying" neither will we..

odd remnant
#

Or does it mean that when you create the SurvivalManager class, you make sure it's Pascal Case. But when you reference it in another script, it's _survivalManager?

rocky canyon
#

conventions are pretty flexible

#

just stick to a standard

odd remnant
#

I understand that. But maybe a better question is: when at the top of my UIManager class I include:
[SerializeField] private SurvivalManager _survivalManager;

What...am I doing? I'm creating a...what? Field?

#

And "should" it be static because it will never change?

rocky canyon
#

it could be static... i personally use singleton patterns

#

that way theres no mistakes..

#

if theres multiples by accident it gets cleared up

odd remnant
#

I would in this case but the game will be MP. Which if I'm understanding right, I couldn't use the singleton pattern. (I'm gonna say up front though, that I haven't even broached the MP element yet, so I might be way way off)

rocky canyon
#

i personally still use camelCase for private class variables

#

this is the convention i tend to follow

odd remnant
#

I'll use the singleton pattern for my "WaveManager" that manages enemy waves of increasing power.

#

I actually like this a LOT more than putting an underscore before every. Single. private. field.

#

I did this for the SurvivalManager after reading the C# documentation and I hated it

rocky canyon
#

yup.. i dont like _ or the m_

#

i use those for method parameters. b/c i have fewer of those

#

void SetHP(int _newHP)

odd remnant
#

Cool. Thanks for this.

rocky canyon
#

the countdown bullcrap at the bottom is just residual context from my last AI session.. i have my AI reformat my code for me quite a bit

#

so it has my nameing convention memorized

#

@odd remnant there happens to be a Unity doc for naming convention as well as teh C# one..

#

thast how i put mine together.. ill see if icant find it right quick

odd remnant
#

That'd be great. ❤️

rocky canyon
#

here ya go

#

aye... i did it right!

#

the best advice i can give u.. is don't go all cryptic..

#

i hate when ppl code with letters and integers

odd remnant
#

100%. One of my prides is clear, clean code with just enough commenting to help explain big decisions, and remind Future Max to come back and fix his past terrible, terrible mistakes.

rocky canyon
#

ive slowly been getting better at readibility

#

the easier it is to read the code (mainly for good naming) the less comments u need as well

odd remnant
#

It takes time and experience to realize "oh shit...maybe I should have done..."

#

Even stuff like in-line curly-brackets can make a difference.

rocky canyon
#

lmao.. good thing i've spent 50% of my 4 years learning doing absolutely nothing but refactoring my code 😬

odd remnant
#

Personally I despise when people do:

else
{```
#

ONE missing tab and you're gonna lose track of that else somewhere.

rocky canyon
#

well,, you'll hate me 😄

odd remnant
#

Hahahaha

rocky canyon
#

all my conditionals are new lines

odd remnant
#

I MEAN 😡 😡 😡 😡 😡

rocky canyon
#

its easier to read!

odd remnant
#

It is, kinda. I'll admit.

rocky canyon
#

i mean cmon look at that ^

rocky canyon
odd remnant
#

Occasionally. I haven't had much need for them, but I will soon when we get into collisions.

rocky canyon
#

how long you been learning Unity so far? im curious

odd remnant
#

I should be working on the base game mechanics and making the game fun. But there's a piece of me that constantly nags about elements like UI and core mechanics.

#

1 week?

#

Maybe 2?

rocky canyon
#

bro.. str8 gangsta lol

odd remnant
#

Hahahaha

rocky canyon
#

keep doing u 👍

rocky canyon
#

but it'll definitely pay off

odd remnant
#

I had experience about 10 years ago in uni, studied game dev and design. But we worked in the professors' proprietary engines instead of a mainline engine.

rocky canyon
#

wait til u start writing editor scripts

odd remnant
#

But yeah, this is the most serious I've been at it.

rocky canyon
#

thats a rabbit hole i try to stay away from

#

i fall in and u wont see me for weeks

odd remnant
#

Haven't heard the term yet. I'm curious.

rocky canyon
#

the Unity editor is 100 percent customizeable

#

you can write your own Editor scripts..

#

that make ur normal game developing easier for example

odd remnant
#

I've been thinking about this, and meant to ask here about it. Sometimes Visual Studio has ZERO context that I'm developing a Unity game.

#

And other times, it has TONS of context.

#

What am I doing wrong?

rocky canyon
#

nah i kid, i kid..

odd remnant
#

Aww, really?

rocky canyon
#

ive been hearing alot of that lately..

odd remnant
#

I like studio. :3

rocky canyon
#

tabbing in and out..

#

may or may not set it straight..

#

ive been having a problem where tooltips and stuff from VSStudio get stuck on the screen

#

not until i force close it do they disappear... 2 months of that and i swapped back to Code vscode

odd remnant
rocky canyon
#

Rider is free now for non-commercial 😉

odd remnant
#

Like here.

#

It doesn't know that "Image" is a class.

#

Nor does it recognize [SerializeField]

slender nymph
#

make sure that your !IDE is configured 👇

rocky canyon
#

do you have the using UnityEngine.UI; namespace?

eternal falconBOT
rocky canyon
#

i think Image needs the UI namespace

#

but i cant remember for sure

odd remnant
#

It still doesn't like it. But lemme try the IDE Config. I was sure I'd done this before.

#

Yeah mine's installed.

slender nymph
odd remnant
#

K. I'll try the first link, then the second. ❤️

slender nymph
rocky canyon
#

but i was correct.. Image needs the UnityEngine.UI namespace

odd remnant
rocky canyon
#

one of the many reasons I believe Unity is the ultimate prototyping/sandbox

#

if u can imagine it u can build it

#

oh.. soo Unreal has this (1) tool that Unity doesn't? Hold my beer

north kiln
#

You can use Search to search layers, no scripting required

#

Ctrl-K

rocky canyon
#

very true.. lol.. live and learn

#

the search feature on unity is actually pretty incredible now imo

odd remnant
#

HOO BOY, another "best practices" question: In a multiplayer game, are Managers unique to each player (like SurvivalManager and UIManager) children of the Player object in the scene hierarchy? Or do they sit elsewhere?

wintry quarry
#

That's way too vague of a question

#

every game handles things differently

#

Also "multiplayer" is vague - are you talking about splitscreen or networked multiplayer

odd remnant
#

Networked.

#

(Good point, I hadn't thought about the different types of MP)

wintry quarry
#

in a networked game there's only one UI

#

there's no reason to have a UI object for players owned by other people on other computers.

odd remnant
#

Woah, ok. That's NOT how I understood how games worked. I figured the UI was a client-side element, and so there would be some kind of "local" object managing the UI client-side, and a then a "server" object running elsewhere that passed information to the client. This is an area I haven't researched or done enough tutorials on yet, so I'm maybe jumping into the deep end too quickly.

wintry quarry
#

the information the Ui is displaying - that could come from all kinds of places

harsh haven
#

Ts pissing me off becuase it seems like it should be so easy

#

I understand i cannot set transform like that

#

I have looked up how to do it like 10 fking times

#

And they literally just do exactly what i wrote

#

and it works

#

I cannot find a solution to this

#

All i want to do is set the transform of the current object

#

Oh my god

#

Every single unity discussion post i go to provides a solution that does not work

#

Yo Holdup

#

I might be slow

#

Actually in that screenshot im doing == which is wrong

#

but i changed that later, just a single = still does not work

#

this is more accurately the problem

#

Like why does every discussion post i go to write the exact same code as me and get no errors???? ive been searching for what makes mine different for like 20 minutes

whole osprey
#

That is not the exact same code. In your final screengrab anyway, you are trying to just change the x component of the vector. The components of the Vector3 struct are not able to be written to directly.

This will work for your case:

Vector3 pos = transform.position;
pos.x = 8f - size/2;
transform.position = pos;
harsh haven
#

why can't i do something like gameObject.transform.position.x

#

or this.transform.position.x

#

or idk

#

Some type of way to do it in one line

#

by referencing the current gameobject

polar acorn
# harsh haven

Okay, you're checking if the X position is equal to 8f - size/2 then doing nothing with that result

harsh haven
#

in that screenshot

#

i reposted what im actually trying to do

polar acorn
# harsh haven

You cannot both get and set an individual property of a vector in the same line. transform.position returns a copy of the vector, since it is a property, not a variable.

You need to store the vector in a variable, then modify it, then set transform.position to that vector

harsh haven
#

ok thank both of u

#

makes sense

polar acorn
#

Or you could set the entire vector at once, transform.position = new Vector3(...

harsh haven
#

I just don't understand why pepole on the internet did what i did and got no errors

#

not just in that screenshot in multiple videos and other places

#

so strange

polar acorn
rocky canyon
#

no one could

#

ohh u said able to do..

#

true story

polar acorn
rocky canyon
#

hey digi.. do u copy the entire value and modifiy it?

#

or do u construct a new one?

#

i wanna know ur ways 👀 lol

harsh haven
#

so thats why it worked

polar acorn
rocky canyon
polar acorn
#

Sometimes it makes sense to make a new vector, sometimes it makes sense to store it first

rocky canyon
#

ahhh yea you're right

#

it depends

#

law of gamedev

celest flax
#

I'm currently trying to make a behaviour tree for the first time. Would people generally recommend working on the classes for all nodes in the same script or in separate ones?

cosmic dagger
acoustic belfry
#

Hey i been struggling with smt. My current dialogue system is fully hard-coded wich is slighty frustating meaning i need to make an army of scripts for each single Npc and interaction. I been trying to make it modular but i get confused and doesnt work. My teacher recommended using Xml as a DataBase wich made sense but seemed harded...

Idk what to do

eager elm
#

You could use ScriptableObjects to hold the texts or use a dialogue system like YarnSpinner.

rich adder
#

Ink is free

warm mason
#

Not exactly code question per se, but how can i add a custom mesh collider to a model i created in blender? what would the process of this look like

polar acorn
rich adder
warm mason
pliant dune
#

hey yall, im trying to make a dialoguebox so when you press the interact button inside this specific box, a specific dialogue will trigger

the ontrigger works and detects the player entering, it can detect when the player presses "interact", but it doesn't output the message when both happens

i think what is happening is that it checks as soon as you enter and then never again, which is not what im looking for, i tried setting the first if to a 'while' but that crashed unity

#

i am going to save, and change that second if to a while and see what happens, wish me luck

polar acorn
#

While loops run to completion

pliant dune
#

it... didn't

polar acorn
#

Well, then it never reached the while

pliant dune
#

yeah

#

why is that then?

polar acorn
#

When a while loop runs, the code inside the loop is the only code that can happen

#

if the code in the loop does not eventually make the condition false, it will crash

rich adder
polar acorn
#

OnTriggerEnter runs the frame this object enters the trigger.
GetButtonDown runs the frame you start pressing the button.

Checking both means that you're going to need to hit the interact button the exact frame you enter the trigger

#

not likely.

rich adder
#

use a boolean for OnTriggerEnter / Exit and use that in Update for Keypress
something like isInTrigger = true

pliant dune
#

thats what i thought was happening, so im gonna need to look for something that isn't getbuttondown, or something that constantly checks rather than just triggering once

rich adder
polar acorn
#

Fair, you'd still potentially skip a button press

#

Using a bool in enter/exit is probably the better choice

pliant dune
#

i wonder how many of these dialogue scripts i can have constantly checking to see if the player is in the boxes does to the performance, probably want to turn them off when the player isn't near

rich adder
pliant dune
#

honestly this is just for a uni project, ill check when i develop this game a bit more to see how much the computers there can tank

rich adder
#

often its a non-issue , computers today are very powerful

#

bool checks are fairly inexpensive and unity already does the OnTrigger messages

pliant dune
#

hell yeah, thank you friends for your help

summer forum
#

is drag changed to damping or am i tweaking?

north kiln
#

Yes

frigid sequoia
#

What is like, the sintaxis to cast a Renderer as a SpriteMask? I am too dumb to freaking find it lol

north kiln
#

It's just normal cast syntax, nothing special at all?
(SpriteMask)renderer

frigid sequoia
#

Ye, I was trying to do renderer(SpriteMask) and was not working, thxs

north kiln
#

It's very strange to be making up new syntax at this point, haven't you been programming for ages lol

frigid sequoia
#

Not that much really, I stopped for a while, and casting stuff is not a thing I do often so....

#

As you can see I am far for a pro lol

twin pivot
#
public interface IPointerUpHandler : IEventSystemHandler
{
    private void OnPointerUp(PointerEventData cursorData)
    {
        Debug.Log("trigger");
        if (((int)cursorData.button) == 1)
        {
            Debug.Log("rmb down");
        }
    }
}

am I doing something wrong? no debug msg is getting sent

rich adder
#

Wait also did you not put this in a Monobehavior script?

#

Idk what the top two lines you wrote for lol

#

I'd be more like
public class MySctipt : Monobehaviour , IPointerUpHandler, IPointerDownHandler

#

spelling errors probably , I'm on mobile rn lol

twin pivot
rich adder
twin pivot
rich adder
#

Yes you need to implement the method associated with that interface

#

Your IDE should be able to insert that for you if you ctrl + . On the red underline in the Ipointer part

twin pivot
#

ah thanks

rich adder
rocky canyon
#

factomondoz

twin pivot
dusty oracle
#

Hey guys i wanna learn how to code but every tutorial is getting me no where can u help?

wintry quarry
dusty oracle
#

yeah i just stared coding in unity i was wondering if u know how i can learn better of faster

polar acorn
#

Do more tutorials

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

polar acorn
#

Or pay thousands of dollars for a private tutor.

I charge up front and also expect mileage and per diem

twin pivot
final forge
#

How should I be storing data in tiles for a tilemap like passability, gameObject occupying it, etc? Right now, I have a separate dictionary storing the tiledata mapping a Vector2 to CellData but I know that I could just inherit from the Tile or TileBase class and make my own, any tips?

fresh finch
#

hello! i'm trying to make it so that the player character either falls or experiences a consequence (e.g. disappears/takes damage) for not being on the platform.

i've found a lot of conflicting opinions (and unfort not a lot of helpful tutorials) on the most long-term efficient way to implement this, so i thought i'd pop in here for some extra advice!

e.g.

  • 2.5D (doing everything 3D and using Z axis manipulation to make it seem like 2D?)
  • OnTrigger-based collisions/scripts (Easier for me to understand/I've practiced this more, but I'm worried it would be inefficient with every individual platform?)
  • Raycasting/layermasking? (seems promising! but I'm sort of confused about how to apply it consistently over a flat plane for this specific prototype)
  • OverlapBox (similar to above -- Switch & Case may be helpful here to save on processing from what I've seen? As opposed to the dreaded ten million If-Else's)

currently the rigidbody2d gravity is set to 0 for the top down appearance, attached a video below + i can attach code of the player movement & dashing script if that helps! any input at all is really appreciated :]

rocky canyon
#

seems like a triggers and colliders would be sufficient enough..
and since its top down you can shrink the size of the cube a bit when not on the platform to simulate it falling (being farther from camera)

#

2.5D sounds overly complex unless theres other usecases for ur game..
raycasting seems pointless in this scenario..
idk bout overlap box

#

nah, w/ triggers u could have the platforms as the trigger part.. and if u leave that ur not on a platform..
youd have an enter method on each of em for platforms.. (i dont see why it wouldn't be performant)
it'd be silly to have the triggers everywhere but the platforms imo unless we were to see some more context of the level designs and what gameplay is

fresh finch
#

Peeking i seeee. yeah tbh I'm trying to prototype something with inspo from Hyperlight Drifter and playing around until i land on a core loop that feels good

#

should i be writing something like an OnTriggerEnter if-else statement?

rocky canyon
#

yea, i think ur overthinking it.. for now i'd just chose a method and go with it.. if u structure the game right.. and design mechanics in pieces then u shouldn't be that hard to swap over the platform/not platform detection whenever you feel like it

#

OnTriggerEnter -> onPlatform = true;
OnTriggerExit -> onPlatform = false;

#

then do w/e u need with that boolean

fresh finch
#

ohoooo i seeeee !! CatYes

#

okay thank you so much!!

twin pivot
twin pivot
rich adder
#

interface is a "contract" on the implemented class, it basically forces the class to implement the methods or properties in the declared interface

#

this ensures that anything that implements an interfaces always has those methods associated with that interface

twin pivot
#

that was what I was trying to say except 100 times worse XD

rich adder
#

the interfaces themselves never have code in the body of a method

#

its up to the class how to proceed with the code inside

#

from link I sent you can see perfect example with common use which is an IDamageable interface

twin pivot
#

thats actually why i called it a reverse method

#

the class itself does the values not the script calling the interface (im kinda shit at explaining things sry)

rich adder
#

its not about being shit at explaining, you just have to learn the specific terms lol

#

script calling the interface , there is no calling here.
it "Implements" the interface

twin pivot
#

what i still dont understand is why this isnt working

    public void OnPointerUp(PointerEventData eventData)
    {
        Debug.Log("eeeee");
        if (((int)eventData.button) == 1)
        {
            Debug.Log("rmb down");
        }
    }
#

Is it still depending on the collider to detect for right clicks?

rich adder
#

it would be good idea to also explain the exact use case of what you're trying to do

twin pivot
#

public class PlayerManagerf : MonoBehaviour, IPointerUpHandler

#

i'm just trying to use the _player gameobject as a button

rich adder
twin pivot
#

this is the correct one, yes?

rich adder
twin pivot
#

mustve glossed it over, lemme go do that

twin pivot
rocky canyon
#

i think for world objects yea

twin pivot
#

Oh I understand the problem now, I'm already using the collider to detect for left clicks and it cant actively detect both

#

(atleast I think thats the issue)

acoustic belfry