#💻┃code-beginner

1 messages · Page 556 of 1

north kiln
#

The top of Local bounds may do, then transform the result to world

late burrow
#

i noticed one script that is able to display its variables as string, but when i do something.AsString = "abc" it actually writes it to variable how it does that?

wintry quarry
late burrow
#

it has a custom class normally but its able to convert itself to string AND update itself when string is provided

#

i thought someone was telling me that isnt possible

wintry quarry
#

You're being pretty vague but it sounds like you're just talking about a property:

https://www.w3schools.com/cs/cs_properties.php

late burrow
#

i didnt knew properties can take different type

wintry quarry
late burrow
#

yeah i was doing once a class thats automatically spits out string, but didnt knew i can make this class with a string, and when writing to string

wintry quarry
#

Without specific examples it's not really clear what you're talking about.

naive pawn
naive pawn
rigid tiger
#

w3schools, home of every student and great programming example

burnt vapor
#

Though, to be fair, I guess it matches in terms of how behind Unity is in a way

rigid tiger
#

I think it covers the basics very well 😅 don't discourage people from it kinda deal

languid spire
keen cargo
#

sorry bout the necro, but the reason why GetComponent is called "bad" is due to a common mistake that people make with it, which is calling it within Update()

since you know how Update() is called every frame

naive pawn
#

if you can set explicit references that's usually preferred

keen cargo
#

some form of singleton also works, but have to be a little careful with those too

#

but yea if you know getcomponent doesn't get called often then it's completely fine to use

shell harness
#

Heya, I'm very new to unity and am trying to make Stardew Valley's Journey of the Prairie King in 3D as a learning project. I've run into a roadblock - I don't know what's the best way to make a gun system with different firing types (single fire, a shotgun/burst fire, omnidirectional fire etc.), that dynamically change from pickups. I could keep it simple and change gun prefabs that have a script attached that handles the firing, but I don't think that's the best way.

So far my research has led me to Strategy Pattern using scriptable objects, but I find using scriptable objects for this weird - you'll only have one single firing type, one burst firing type etc., so why a scriptable object?

Could anyone point me in the right direction, how I should be thinking about this, to make it easy to maintain and expand?

shy kite
#

If a 2d collider is a trigger, detects another collider and does something, then i set the object which contains the 2d trigger collider to false then reactivate it in the same state, will it detect the other colliders and do the functions again even tho i didn't move it?

#

i don't wanna have my triggers always active for attacking

#

i tested it but it doesn't seem to work, heck only if the collider is moving is working

#

if my charcater stays still and attacks it doesn't deal dmg

languid spire
shy kite
#

both only work if my character is moving into the other collider

#

they are braindead if they don't

languid spire
#

Are you diabling/enabling within the same FixedUpdate time frame?

shy kite
#

in the collider

#

the trigger is in another collider and it doesn't see it

languid spire
#

try doing this.
in a coroutine
disable the collider
wait for fixedupdate
enable the collider
and see what fires

shy kite
#

but the ontrigger stay should always detect other colliders even tho is not moving right?

languid spire
#

yes, the question is at what point does the collider get added to the 'active' list. For normal colliders this works but I've never tried it with triggers

shy kite
#

the problem is that now i have the trigger always active but works the same

#

could it be because it detects another collider i do not see?

languid spire
#

debug your code to find out

shy kite
#

still works the same

#

i really do not know what might be wrong, this is some begginer ahhh shit

languid spire
#

simple enough to do with a couple of cubes

shy kite
#

there was a bigger collider

#

i was right

#

but now the trigger doesn't detect solid collider

#

i will kms

naive pawn
shy kite
#

OMFG

naive pawn
#

rbs control physics, including collisions

shy kite
#

i will add it rn, my savin angel

languid spire
#

Did you not go and read the docs about collision and trigger requirements?

naive pawn
#

and that's why you're getting easy-to-fix issues

languid spire
shy kite
#

Succes means hard work

#

not reading essays

#

😎

languid spire
#

WRONG

naive pawn
#

lmao no

#

there are giants waiting for you to stand on them

quick fractal
#

If you don't read the docs, you won't ever move away from relying on other people to provide basic information

naive pawn
#

stand on their shoulders

quick fractal
#

They're there to help. If they were all one word answers no one would find them all that helpful

naive pawn
#

coding in particular is half reading

#

reading docs, reading errors, reading warnings, reading logs

#

reading examples and explanations

#

but all skills involve learning

#

and people have done hard work for you already, and condensed that knowledge

#

if you refuse to learn from other people, you're just going to repeat their mistakes

#

resources exist for a reason, use them

shy kite
languid spire
shy kite
#

coding is like 90% readin code

quick fractal
#

100%. No writing involved.

languid spire
quick fractal
#

For the first 5 minutes, maybe*

rich egret
languid spire
naive pawn
#

and can't really help without any info

rich egret
naive pawn
#

well there's something blocking it there i guess

rich egret
#

Could something be causing it to get stuck?

naive pawn
#

i don't think that's a code issue

#

are you using a tilemap there?

rich egret
#

yup

naive pawn
#

do you have a composite collider on the tilemap?

naive pawn
naive pawn
#

and the tilemap collider is set as part of the composite?

#

you have not set it as part of the composite

rich egret
naive pawn
#

ok, let's try again.. do you have a composite collider on the tilemap

rich egret
#

no, just tilemap collider 2d

#

as you can see

naive pawn
#

no i can't see because you only showed that lmao

#

add a composite collider and set the tilemap collider to be used by the composite

shy kite
naive pawn
#

that wouldn't really work

naive pawn
#

can't skim, can't rewind easily, can't search

naive pawn
rich egret
#

ok

languid spire
rich egret
naive pawn
rich egret
#

kk

#

wow thank you bro

#

you saved me

#

❤️

tired junco
#

hey im updating my renderer feature to unity 6 atm and im wondering what would be the equivalant to this now?

#

so how to get the current camera

#

SOLVED: var cameraData = frameData.Get<UniversalCameraData>();

green flame
#

Hello! Someone can tell me how to do a "setTimeout" in csharp with a cb ? I found some thing like "IEnumerator<WaitForSeconds>" but it's not working ^^

naive pawn
#

in unity, you could use coroutines

#

that's the path you're going towards

#

try googling coroutines

#

what do you mean by "cb" there?

green flame
#

Callback ^^

naive pawn
#

ah, of course. brainfarted lmao

#

if you want a lambda, you could use tasks?
but i'd recommend just going with coroutines, they're really flexible

green flame
#

Ok thank you, I'm reading how to use it 🙂

idle juniper
burnt vapor
# green flame Hello! Someone can tell me how to do a "setTimeout" in csharp with a cb ? I foun...

Coroutines have build in yield commands to wait specific times, but Unity also supports Tasks.

public async Task M()
{
    await Task.Delay(1000);

    // Callback here.
}

Alternative non-async Task approach which runs in the background.

public void M()
{
    _ = Task.Delay(1000)
        .ContinueWith((task) =>
        {
            // Make sure to await the task to catch exceptions.
            _ = task.GetAwaiter().GetResult();

            // Callback here.
        });
}
#

Note that due to threading, you can't invoke Unity methods in here unless you run it on the main thread

#

Depending on your situation, you place the callback after the delay finishes

burnt vapor
idle juniper
#

i want when i hit space hitPosition and attackSlider.value are the same but, when i do it randomly switches value

naive pawn
#

you're checking for space after MoveSlider, so it's gonna be different from the previous frame

burnt vapor
idle juniper
naive pawn
#

MoveSlider seems to be responsible for that

green flame
naive pawn
#

or some other change that isn't logged

burnt vapor
# idle juniper

So After is the current situation? I'm confused because it seems correct

wintry quarry
#

Yeah i'm not seeing what's wrong there...

burnt vapor
wintry quarry
#

Also sdoes your slider happen to have an OnValueChanged listener?

idle juniper
#

this is the value

burnt vapor
#

If you're confused why the two are not the same then that's because MoveSlider adds sliderSpeed * Time.deltaTime to attackSlider.value as long as isAttacking is true

idle juniper
#

aaaa, so attackSlider.value is not gving the same value

burnt vapor
#

Nop

#

Would love to fix the code but I don't know all the context of it

#

What it does etc

idle juniper
#

so there is a slider that moves to the end, when pressing space it will stop at one point aka grabbing the value it is ant and then setting a damige if it is in the correct raige

#

doce that make sens?

#

can i post videos

#

here?

burnt vapor
#

Sure thing

idle juniper
#

if that makes sens

obsidian plaza
# idle juniper

can u tell me a hit position value that always gives this bug?

idle juniper
#

all

#

if 90% = 0.9 it will give a random value like 0.003 0.005

#

and so on

obsidian plaza
#

oh ok

#

wait so

#

wdym by %90

#

according to your code it goes 0 damage, then 5, 10, 5 again, then 0

#

but visually it looks different

#

and wdym it returns a float? i thought it returned damage number

#

mayb im just slow think im looking at smtn else

idle juniper
#

it is a slider so when i mean 90 i mean 90% of the slider is full

and i set that value so 0.9 to hitposion aka were did the player hit but for some reson form procent it changes when hitting space and then just shouts out jargin

#

before is in procent
the after idk

obsidian plaza
#

gotchu

idle juniper
#

and i dont know why this happens due to there is no point in the code where slider gets effected

#

it just happens when the next part is called

obsidian plaza
#

where do u do math with the slider

#

before capturing the hitposition

#

is this the only place

idle juniper
#

hold on

#

1s

#

i did some changes and forgot to update it

#

was still trying to fine out why the value changes

#

but still no luck

obsidian plaza
#

this logs the same error?

idle juniper
#

so were moving slider is the math behinde the slider moving forword aka how much of the slider has moved form 0 to 1
and slider value is the same value is that aka if slider is 50% full then value is 0.5 for both
and when space is pressed it is seposto just use the last value

idle juniper
swift crag
# idle juniper

You have "Collapse" turned on, which can cause misleading results.

#

This causes identical log messages to be combined together

#

I wouldn't expect it to happen here, though, because these numbers have a lot of decimal places

#

Although, I guess there's one thing to note

#

If you try to move a slider past its max value, it will get set to exactly its max value

#

using Mathf.Repeat will then give you a value of zero

obsidian plaza
#

i think thats what they want

swift crag
#

So this would cause a lot of zeroes

#

suppose your slider is at 90%

#

you add 15% to it in one frame

#

The correct position for the slider should be 5%

obsidian plaza
#

i dont see how its possible that these two could give different results

swift crag
#

This looks fine, yes

obsidian plaza
#

so the value is taken correctly when you press space

#

but after that it breaks

idle juniper
#

ye

idle juniper
#

sorry i am still new and some stuff fucks me over

swift crag
#

that sounds like maxValue is 0.9, then

#

Also, you turned off Collapse in the console, correct?

obsidian plaza
#

how is the code even still going after you hit space?

#

it shouldnt log anything after

idle juniper
#

button

obsidian plaza
#

what

idle juniper
swift crag
#

MoveSlider also happens to log "Space Pressed at Value:"

#

which is misleading

obsidian plaza
# idle juniper

so ur pressing the attack button to attack, not hitting space bar?

#

whats that button do

idle juniper
idle juniper
swift crag
#

I don't understand what the actual problem is right now

obsidian plaza
#

do if you hit start and hit space, it works fine. But if you then hit the button to restart, the values are wrong

obsidian plaza
idle juniper
#

is there a vc one can jump into?

#

to i can explane it a bit better

swift crag
#

no, you just need to explain it better here

swift crag
# idle juniper

i just realized that my music was completely covering up your voice lmao

#

i thought the video was silent

#

gimme a minute

#

my bad

idle juniper
#

its a slider meaning one can move it form 0 to 1, 0 meaning 0% and 1 meaning 100%. sliders work in procent when askig for its value. so we say we move the slider to around 90% meaning that we have move the slider to 90 of the way

#

why the fuck is it see thrue

#

when did paint do that

idle juniper
rocky wyvern
#

It’s possible the slider value only changes at the end of the cycle or something like that

obsidian plaza
#

im making a rhythm game that is almost exactly like this

#

for one, im not sure how accurate sliders are in value

swift crag
#

discord plays videos very quietly for some reason

obsidian plaza
#

what i do is i take the position

#

but besides that

swift crag
#

Can you inspect the slider? I want to make sure its max value is exactly 1

#

It looks like it's currently 0.9

obsidian plaza
#

how ur english is perfect but writing less than perfect

swift crag
#

Okay, so the slider has the right max value

idle juniper
idle juniper
swift crag
#

It looks to me like it is wrapping around at 0.9 instead of 1.0

rocky wyvern
#

So you want a random value from 0-1 and it’s actually 0-0.9??

obsidian plaza
#

according to zion, all the values are wrong

#

@idle juniper can u send a vid of the bug happening

#

like u pressing attack

#

and it logs wrong

swift crag
#

One frame before hitting space, the value was almost 0.9

obsidian plaza
#

so it stopped

idle juniper
#

do you guys just want the build?

obsidian plaza
#

they hit space at 0.9, then reset it

#

headache to download tho

#

seems like easy fix

swift crag
#

This is the only line that actually involved hitting the spacebar

#

This is getting logged every frame by MoveSlider

obsidian plaza
swift crag
#

It has nothing to do with hitting space

obsidian plaza
#

wait

#

oh

#

lol

swift crag
# idle juniper

Everything in this example looks fine except for the fact that it wrapped around too early

#

Hang on a second..

#

Do you have two AttackSystems running at the same time here?

idle juniper
#

no

swift crag
#

I'd expect to see more log messages (now that Collapse is off, at least), but they 're not appearing

#

ah, I have one other idea here

#

fightButton.onClick.AddListener(StartAttack);

#

If you have the fight button selected, hitting space will press it

#

That's got to be it.

#

This will call StartAttack, which resets the slider value to 0

#

Then MoveSlider runs and advances the slider a tiny bit

#

This gives you a bogus value

rocky wyvern
#

Bogus

idle juniper
#

thank the lord that makes sens

obsidian plaza
#

why does anyone use listeners? why not just use OnPointerClick?

swift crag
#

I kind of prefer to subscribe via code

#

especially if I already need a button reference for some other purpose

#

Consider making the Fight button non-interactable during the minigame

#

someButton.interactable = false;

idle juniper
#

so what is the best way of fixing this

#

or going about fixing this

swift crag
#

Don't let the player press the fight button a second time

swift crag
#

You could also do nothing in StartAttack if you are already attacking

#

The problem is that, when you click a button, it also gets selected

#

this is important for keyboard/controller navigation

#

but, in our case, it also means that the button is now going to get pressed if we hit space or enter

idle juniper
#

THANK YOU GUYS SO MUCH!

swift crag
#

that was a tricky "gotcha" with the UI button

#

if I hadn't noticed that, I'd eventually have suggested adding a few more log statements, including one in StartAttack

#

(to test the idea that you had a second AttackSystem somewhere)

#

Also, I'd tweak it slightly

#
float progress = slider.value + Time.deltaTime;
progress = Mathf.Repeat(progress, slider.maxValue);
slider.value = progress;
#

imagine the slider moves by 40% per frame and it's at 80% right now

#

as-is, you set the slider value to 0.8 + 0.4, which is 1.2, and that gets clamped to 1.0 (because that is the max slider value)

#

so after the repeat, you get 0.0

#

It should be 0.2 after the repeat

rocky wyvern
#

Also I think onpointerdown is all mouse buttons

swift crag
#

that wouldn't be useful here; the AttackSystem is not the thing you click on

#

I was thinking about adding a persistent listener in the button's inspector

obsidian plaza
#

For all my buttons i just put a sprite renderer, then put an invisible image with raycast behind it

#

then i give it a script and do OnPointerClick with event systems

#

i handle all the sprite changes on hover manually and everything

#

gives me freedom

rocky wyvern
#

How’s it any different in terms of ability for that to using a delegate

rocky wyvern
#

Like
A variable that stores a reference to a method

#

I guess saying delegate wasn’t completely true to how you use the system

#

The onclick one that is

obsidian plaza
#

like it has to be in update

#

instead of onclick, do function

minor radish
#

How to downlaod manualy the recent version of visual studio in unity or how to get IDE for visual studio ?

eternal falconBOT
rocky wyvern
#

From what you said earlier are you not somewhat familiar with events in scripting?

obsidian plaza
#

not very familiar with the listening thing

wintry quarry
#

Delegates run whenever you invoke them. No more, no less.

swift crag
#

i feel like we're talking about three unrelated things here

rocky wyvern
#

Yeah pretty unrelated just surprised they don’t know

rocky wyvern
#

Like for example you can set the delegate ‘variable’ to store a method and call it from there
// the definition of the delegate
public delegate void FooDelegate(int number);
// declaring a delegate
public FooDelegate MyFooDelegate;

public void Start()
{
MyFooDelegate = DoStuff;
}

DoStuff(int number)
{
Debug.Log(number)
}

#

Idk where backtick is on phone

#

How it relates to events is delegates can store multiple methods basically

#

So to ‘listen’ to the delegate you += the method you want to run to that delegate

obsidian plaza
#

o yea idk what this is

#

the delegate

#

ill google

#

wait yes i do

#

is delegate just an invisible word

#

ive never seen it

rocky wyvern
#

What do you mean

#

Invisible word

obsidian plaza
#

like if you type "bool x"

#

its really private bool x

naive pawn
#

it's not implicit, no

#

nor is it default

rocky wyvern
#

I mean you use the word itself like that yes but that’s essentially for the compiler to understand wtf ur writing and that you’re not trying to declare an actual method

swift crag
#

delegate is a keyword.

#

You don't see it very often, though

obsidian plaza
#

ok then i really dont get it

swift crag
#

You generally just use pre-defined types, such as System.Action

#

It's used to declare a delegate type.

rocky wyvern
#

Quite literally

#

It is a variable that stores methods

#

That’s it

swift crag
#

System.Action is a zero-argument function that returns nothing, for example.

#

System.Func<int, float> is a one-argument function that takes an int and returns a float

rocky wyvern
#

Like say you have an update that needs to DoStuff() every frame, and you want to switch out what stuff it does

#

You could potentially call the method stored in a delegate

#

And change the method the delegate is storing to decide what method to run

obsidian plaza
#

so why not do DelegateMethod("Hello World") in this case?

swift crag
#

because you can pass in any matching method of your choosing

wintry quarry
swift crag
#

For example, I have a validation system that does this

#
public void Check(System.Action<string> onFail) {
  if (bad) {
     onFail("OH MY GOD");
  }
}
#

very loosely

#

I can then do this

#
public void HandleFail(string message) {
  Debug.Log(message);
  // do other stuff
}

// ... somewhere else in my code 

Check(HandleFail);
obsidian plaza
#

wtf

rocky wyvern
#

if (bad)
{
bad = false;
}

swift crag
#

true smart

swift crag
obsidian plaza
#

my brain is halfway there i think

timber tide
#

delegates when I want to make my code look pretty

swift crag
#
public void Foo(float x) { return x + 1; }
public void Bar(System.Func<float> y) { return y() + 1; }

one function takes a float.
one function takes another function that returns a float

timber tide
#

usually people recommend you to use delegates from referencing upwards, but that's too much effort. I just bi-directional reference everything

swift crag
#

i don't understand what you mean by that

rocky wyvern
#

In class heirarchy I think

#

But it really isn’t that much effort

#

I don’t think it’s more effort at all actually

timber tide
#

imagine making an inventory, your slots shouldnt have a reference to the inventory itself but a delegate to invoke from the inventory

rocky wyvern
#

Just a different architecture or way of thinking about communicating between classes

swift crag
#

other objects can give you delegates to invoke

#

(but only you get to invoke them)

rich egret
#
    {
        if (target == null) return;
        float directionToPlayer = target.position.x - transform.position.x;
        bool shouldFaceRight = directionToPlayer > 0;
        if (shouldFaceRight != isFacingRight)
        {
            Flip();
        }
    }

   void Flip()
    {
        isFacingRight = !isFacingRight;
        SpriteRenderer spriteRenderer = GetComponent<SpriteRenderer>();
        if (spriteRenderer != null)
        {
            spriteRenderer.flipX = !spriteRenderer.flipX;
        }
    }

Someone know why the enemy is not does Flip?

burnt vapor
#

If you want help I suggest you start by debugging all of these

languid spire
burnt vapor
#

Alternatively, if you already did this it would help if you mention it all gets called and you confirm spriteRenderer.flipX = !spriteRenderer.flipX; is invoked

wintry quarry
snow warren
#

hello guys
non unity question but C# related
I have <Nullable>enable</Nullable> inside my visual studio project
I can use Nullable but not NullableContext
Am i missing something here?

#

i shall be thankful if you can help me

short hazel
#

Ensure you have the right using directives*

wintry quarry
short hazel
snow warren
#

it tells me to download the microsft.codenanalysis package

short hazel
#

You should be using the ? notation instead of fiddling with these attributes btw

snow warren
#

but i think there is no need for thirdparty package right?

short hazel
#

From the docs I linked

snow warren
#

are you sure its just for compilers because from what i heard its also used for nullable types and their assignment

short hazel
#

If you need to mark a reference type as nullable then postfix it with ?, else don't

#

eg. string? and string

snow warren
short hazel
rich egret
#

This does a flip in the opposite direction

wintry quarry
molten robin
#

Is it possible to scroll between the Lerp value? like this?

  {
        float scrollValue = Mathf.Clamp(camDistance + Mouse.current.scroll.y.ReadValue() * camDistanceSpeed, 0f, 1f);
        camDistance = Mathf.Lerp(minCamDistance, maxCamDistance, scrollValue);
  }
swift crag
#

Sure.

languid spire
swift crag
#

i'm guessing it's instantly snapping to either 0 or 1

#

(but I can't tell, because no problem was described!)

languid spire
#

tbh not sure

molten robin
#

Yup snapping straight to 1

#

or 0 now that I removed the camDistance from it

swift crag
#

The logic doesn't really make sense

#

You're using the computed camDistance (which is probably not in the 0..1 range) to compute the lerp factor

#

Perhaps you meant to keep track of scrollValue.

languid spire
#

not quite sure what camDistance + Mouse.current.scroll.y.ReadValue() is supposed to do

#

why + ?

swift crag
#

using camDistance at all is nonsense here

languid spire
#

correct me if i'm wrong but scroll.y is -1, 0 or 1

swift crag
#

The magnitude depends on how you're getting scroll input

molten robin
swift crag
#

notably, my macbook's trackpad produces many very tiny scroll events

#

this causes the Shader Graph window to zoom in and out at absurd speeds, because it changes the zoom by a fixed amount

#

instead of respecting the strength of the scroll

languid spire
#

pretty sure windows doesnt do that

rocky wyvern
#

Windows does that

#

Trackpads are so ass for usability

languid spire
#

hey, accessibility, we have to respect that

#

I'm guessing the new Input system has some form of normalizing the input values

swift crag
#

you just need to respect the magnitude of the scroll event

#

instead of only looking at the sign

#

(notably, Smugliif, your code works correctly already)

molten robin
#

thanks for the help, i haven't really done much coding in a while

swift crag
#

It's useful to think about "units" here

#

cameraDistance is measured in meters, whilst scrollValue is a unitless percentage

#

That can help you catch errors like this

late burrow
#

i really really wish property could hold some value is there no way to perform that

naive pawn
#

what do you mean

#

what are you trying to do, what problem are you having

late burrow
#

like i would use them for many things, but 90% of time its just passing values with ifs

#

and thats twice as many code

slender nymph
#

what does that even mean

late burrow
#

get if not null

#

simply i wanted treat it to value BUT do something under some condition

naive pawn
#

can you show an example of your intended usage

slender nymph
fervent abyss
#

is

        get {
            Physics.Raycast(Body.position, Vector3.down, out RaycastHit hit, raycastDistance, raycastLayer.value);
            return 1*(90 - hit.distance);
        }
    }

any different from doing this using a method with float return value?

late burrow
#

dont tell me that isnt how most properties look like

slender nymph
#

well for starters, that isn't even how you check for null. but if the intention is to ensure it is never null or empty when getting it, then yes that is typically what you would do

late burrow
#

and i would gladly use half of my code in properties

#

but you realize how many variables i would have to stick under them

#

why cant it have one internal one

slender nymph
#

if you want a full property then yes, you must have an explicit backing field. that is how properties work. only an auto property wouldn't require an explicit backing field because the compiler generates one for it, but you wouldn't be able to have code inside the getter/setter with that

naive pawn
slender nymph
rocky wyvern
#
  1. The idea is to separate full on actions and simple data access or editing
  2. Properties are slightly faster
#

You should use a property when setting data and performing functionality DIRECTLY LINKED to that data

#

Say… changing a text size variable; in the property you also change the text size of the linked tmpro component

#

If you are working with multiple different things changing loads of stuff use a method

#

That is the core idea

#

And it means when you use a property you know for sure it won’t change or affect anything else

#

Which leads to easier code readability and debugging if you do it correctly and everyone is on the same page

swift crag
#

I wouldn't expect a property to be any faster. It's invoking a function

#

I guess it doesn't need to resolve a method group into a specific method

mystic lark
#

i am making a coundown timer and cuz the coundown goes slower when it in negatives i just changed and deleted the - is that okay to do or?

frail hawk
#

you need to fix your if statement in the Update instead

rough lynx
#

Yh just change it to 0 if it's less

frail hawk
naive pawn
mystic lark
naive pawn
#

yeah because you told it to do it twice as fast when it's positive

#

read your code

rough lynx
mystic lark
#

i get it i didnt even see , so thats why it goes slower thanks

ruby spire
#

Hey, I currently don't use namespaces in Unity, but Rider recommends me the following namespace because it matches my folder structure. ChatGPT on the other hand tells me that starting with _Project is a bad idea and I should use my game name instead. What's the best practice for Unity projects?

naive pawn
#

there's not really a best practice

#

do you want namespaces? do you have that kind of structure in mind?

#

like, is the folder a whole featureset, or just a grouping?

#

if it's just a grouping, then a namespace might not make sense

#

it would probably not include Scripts or Assets or anything along the path though, maybe the game name if you want it

mystic lark
frail hawk
#

did you look into coroutines 😉

ruby spire
#

it's more for code encapsualtion and also because i want to add assembly definitions later on

mystic lark
snow warren
#

hey
I have a question
is there a way to convert a static gameobject to non static at runtime?

#

i really want to know about this

#

because whenever i go and read about it people say that marking gameobjects static is editor only

stark rune
runic lance
runic lance
#

what do you mean?

snow warren
#
newThing.isStatic = true;
newThing.transform.parent = transform;
StaticBatchingUtility.Combine(gameObject);```
#

this is how you mean it?

#

i want to ask does it work even when the game is built

runic lance
#

newThing.isStatic = true;
this should be unnecessary, but yes, it will work in builds

snow warren
#

the new one created wont be static anymore

runic lance
#

the static preprocessing is done in the editor or during builds, so you can't create static objects dynamically

#

the closest you get is the StaticBatchingUtility

#

or maybe doing some tricks with wrapping the GameObject in its own scene, but I'm not sure how valuable is this

#

is there something specific you're trying to achieve?

stark rune
runic lance
# stark rune wait is that question to me or another guy?

the other guy, sorry
you add some logs to your code and check exactly what's going on, if the vignette value is being updated correctly
additionally, you should look into the Unity forums or even check here in the Discord search for the correct way to update the vignette – ChatGPT is not reliable and will probably give you bad information

stark rune
runic lance
rich adder
rich adder
#

vigEffect also would throw null if thats not assigned

rich adder
stark rune
#

ok so should i add timue.deltaTime

rich adder
#

well yeah if you want it framerate independent

#

another reason to learn this stuff yourself insted of using a conversational chatbot

stark rune
stark rune
olive galleon
#

When should I use EventHandler or Action for events or anything other than those two, could I just use EventHandler for everything?

rich adder
#

doing the tryGet everyframe might also be overkill. How many times is this thing( PostProcessVolume ) being changed anyway

waxen pendant
#

does OnTriggerEnter get called in the object entering or the object that has the collider with IsTrigger ticked?

slender nymph
#

both

rich adder
stark rune
#

ok sure

waxen pendant
#

oh, for me its isn't getting called in the object for some reason? the box is ticked, the object passes through, but no call

rich adder
stark rune
#

oh ok#

runic lance
#

performance-wise it could be worse since you're creating a new instance of EventArgs everytime you raise the event, so that's something to consider

echo field
#

Hello guys!
I started making a game recently.
It has a node-based movement system and I want to add a simple view bobbing effect to it.
Unfortunately I am unable to implement it.
I do the camera movement with vector3.lerp and it seems that whenever I do that it is the only thing active.
I have an actual boolean set so that whenever I am moving it should activate the headbobbing script.
I'm curous if I can make the camera headbob while learping it from waypoint to waypoint

rich adder
stark rune
#

oh mb

#

oh i just made an other script sepearte with it thx for th ehelp

stark rune
mystic lark
#

is there a way i can acces or copy a local variable to another script?

rich adder
zenith hare
#

hi i just started c# like 2 days ago. i had a command to load the next scene for my 2d game after a fade transition is complete. i have 4 objects which should be fading at the same time, however 2 of them are not fading out. i think since the fade out isnt finishing, its not allowing the next scene to load, but im not sure how to fix it. im using chatgpt to help me, by the way. https://paste.ofcode.org/sTut8u8Lwq7pDg7Lz9QvuX

swift crag
#

Each coroutine will have to complete before the next one can run

slender nymph
zenith hare
#

ohh i see. should i just get rid of the yield returns as a whole to make them fade at the same time?

languid spire
#

more likely one of the methods is throwing an exception which will abort the whole lot

swift crag
zenith hare
swift crag
#

You could pass each one to StartCoroutine to run them separately

#

If they all have the same delay, I'd just do that, then wait for two seconds

#

I'm actually not sure what the best way to say "run all of these coroutines, then wait for them all to complete" is

#

but you can simplify that to "wait for two seconds"

snow warren
#

hey guys does GameObject.Find clones a gameobject as well?

swift crag
#

No. It finds an object.

snow warren
#

i want create something that finds a gameobject and then clone it

swift crag
#

that's all it does

#

You could certainly Instantiate an existing game object

snow warren
#

would this clone the gameobject one time or 2 times?

languid spire
#

once

swift crag
#

again, all that Find does is find an object

snow warren
#

thanks for the help

swift crag
#

it's right in the name (:

rich adder
#

bad Idea to use Find though strings should be avoided for this usecase

#

very flimsy

swift crag
#

What is the use-case here?

#

Presumably you're finding a specific object for a specific reason

snow warren
#

at runtime

swift crag
#

uh oh

#

we're in the "Y" part of an XY problem right now, I think

#

explain what your original goal was

rich adder
#

yes

snow warren
#

i can change it to non static by this code

newThing.isStatic = true;
newThing.transform.parent = transform;
StaticBatchingUtility.Combine(gameObject);```
slender nymph
#

why is it even static in the first place if you intend to make it non-static?

snow warren
slender nymph
#

how . . . ?

snow warren
#

also developing a game that uses baked lightmaps in the form of texture that can be changed using shaders

#

for better computation i am just using cheap alternatives

swift crag
#

I hope you aren't intending to run this code at runtime

snow warren
#

well i am intending

#

i hope it doesnt crash

cosmic dagger
# olive galleon When should I use EventHandler or Action for events or anything other than those...

EventHandler is more conventional and intellisense provides info about the delegate. The issue is EventArgs, it's a class, and you need an instance to send when invoking the event, either by using a current or new instance

Using Action gives you more control with up to 16 parameters, you can pass structs without using a class, and you can replicate an EventHandler by passing the sender as well . . .

swift crag
snow warren
#

i know of someone who pulled this off so i wanna do it as well

#

since he wont tell me

#

hey is there something like Scene inside unity

#

C#?

#

like calling a specific scene and then finiding gameobjects through it

ocean loom
#

hi guys, can someone help me with raycasts i cant seem to get them working. itd be best for me if i could just screenshare to you

runic lance
rich adder
slender nymph
#

if only there were some sort of link that would explain what that means

ocean loom
rich adder
#

wow

slender nymph
#

you're not so good at reading comprehension, huh?

rich adder
#

bro did the complete opposite of what link explains lol

rough lynx
#

Aw man I was gonna link dontasktoask then you already did it

cosmic dagger
slender nymph
#

they directly copy/pasted the what not to do part of the dont ask to ask site and just changed some stuff so it said unity

swift crag
#

that is an interesting response, yes

swift crag
ocean loom
swift crag
#

Show your code

#

You can use one of these paste sites to share the entire script:

#

!code

eternal falconBOT
ocean loom
ocean loom
swift crag
ocean loom
zenith hare
#

i need these two images to be set as an actual image so i can place them into the script which i did. however do i need to keep the 'image' checkbox checked? because when i do, the image just turns into a solid color

swift crag
# ocean loom https://paste.mod.gg/ulmnfnkcidpj/0

okay, so FixedUpdate should be running 50 times per second. You said that you aren't seeing any lines being drawn -- make sure that you have gizmos turned on in the scene view or you won't see those, btw

#

One important thing is that the lines will only last for one frame

slender nymph
swift crag
#

So you'll only actually see them if a FixedUpdate ran during your frame

#

I'd make the line last a bit longer to make sure that's not the issue

#

The fourth argument is the lifetime. You can give it something like 0.5f for half a second

#
Debug.DrawRay(foo, bar, baz, 0.5f);
#

and while we're at it, pass false for the fifth argument

#

This will make sure that the line can't be covered up by other objects in the scene

ocean loom
#

ah okay, ill try that. Thank your very Much!

swift crag
zenith hare
swift crag
#

I don't see why it wouldn't, but if you still don't see a line, do that

slender nymph
#

if it helps to understand, the Image component is how you display a sprite in UI and a SpriteRenderer component is how you display a sprite in the world. use the one you need and refer to that type instead of assuming you need an Image component to reference that object

zenith hare
slender nymph
mighty compass
#

Goodmorning everyone I wish you luck with your code and 0 bugs when implementing new features

zenith hare
slender nymph
#

did you not read what i've said?

slender nymph
#

show your code 😉

swift crag
#

I've seen errors like this caused by a messed-up package cache

zenith hare
slender nymph
#

exactly. this is a code channel

swift crag
#

a Canvas is rendered differently from things like MeshRenderers and SpriteRenderers

mighty compass
#

😂

swift crag
#

that's why you have the Image component -- it's used by a Canvas to render a sprite

#

You don't put a SpriteRenderer under a Canvas -- it'll just kind of..render by itself, and the Canvas will have no clue what to do with it

#

They do both use sprite assets

#

That's what you have in your project window

#

Those are assets.

#

When you import a texture as a Sprite, the importer produces sprite assets

#

Both Image and SpriteRenderer can reference these assets

zenith hare
#

oh i see, tysm, it finally worked

snow warren
#

guys i did something like this but it didnt work

            if(Input.GetKeyDown(KeyCode.O))
            {
                GameObject gameObject = GameObject.Find("HallFurnitureMesh");

                if(!GameObject.Find(gameObject.name + " Removed Restriction"))
                {
                    GameObject NewObject = new GameObject(gameObject.name + " Removed Restriction");
                    NewObject.isStatic = false;
                    NewObject.transform.parent = gameObject.transform.parent;
                    NewObject.transform.localPosition = gameObject.transform.localPosition;
                    NewObject.transform.localRotation = gameObject.transform.localRotation;
                    NewObject.transform.localScale = gameObject.transform.localScale;
                    MeshFilter filter = NewObject.AddComponent<MeshFilter>();
                    filter.mesh = gameObject.GetComponent<MeshFilter>().mesh;
                    MeshRenderer renderer = NewObject.AddComponent<MeshRenderer>();
                    renderer.material = gameObject.GetComponent<MeshRenderer>().material;
                    MeshCollider collider = NewObject.AddComponent<MeshCollider>();
                    collider.sharedMesh = gameObject.GetComponent<MeshCollider>().sharedMesh;

                    gameObject.SetActive(false);
                }
            }```
#

any helps i can get

#

i am stuck

summer stump
#

what do you want to happen (specifically) and what does happen (specifically)

#

And why not use prefabs?

snow warren
# summer stump Define "doesn't work"

i created a clone of a static mesh at runtime
the clone was also static
then i created a new gameobject and assigned its mesh values off of the static gameobject
the new gameobject was again static and this time not visible

#

i dont know how to make a static gameobject to non static

summer stump
snow warren
#

works only in editor

#

not at runtime

summer stump
#

Ah yeah, I saw that on isStatic, but missed it on the other

#

I feel like I would just use a prefab and swap the mesh, not sure

#

Might need to show a bit more of the code

summer stump
#

!code

eternal falconBOT
summer stump
#

It may be what you decided is relevant, but it is not the whole file

analog elbow
#

Not sure if this is the appropriate place for this question. I'm trying to figure out a way to get a nuget package into Unity, and there seems to be a lot of inconsistent information on if you should or how you should do this. Anyone know of a good guide?

snow warren
# summer stump It is clearly not
using UnityEngine;

    public class RestrictionRemover : MonoBehaviour
    {
        void Update()
        {
            if(Input.GetKeyDown(KeyCode.O))
            {
                GameObject gameObject = GameObject.Find("HallFurnitureMesh");

                if(!GameObject.Find(gameObject.name + " Removed Restriction"))
                {
                    GameObject NewObject = new GameObject(gameObject.name + " Removed Restriction");
                    NewObject.isStatic = false;
                    NewObject.transform.parent = gameObject.transform.parent;
                    NewObject.transform.localPosition = gameObject.transform.localPosition;
                    NewObject.transform.localRotation = gameObject.transform.localRotation;
                    NewObject.transform.localScale = gameObject.transform.localScale;
                    MeshFilter filter = NewObject.AddComponent<MeshFilter>();
                    filter.mesh = gameObject.GetComponent<MeshFilter>().mesh;
                    MeshRenderer renderer = NewObject.AddComponent<MeshRenderer>();
                    renderer.material = gameObject.GetComponent<MeshRenderer>().material;
                    MeshCollider collider = NewObject.AddComponent<MeshCollider>();
                    collider.sharedMesh = gameObject.GetComponent<MeshCollider>().sharedMesh;

                    gameObject.SetActive(false);
                }
            }
        }
    }```
#

this is the entire script now

summer stump
analog elbow
#

@summer stump I have no heard of this one, I think there is another one available in the unity asset store, but there were complaints that it was quite slow.

snow warren
summer stump
analog elbow
#

@snow warren just the dll?

snow warren
#

if its mono then either would work because unity compiler will code strip the dlls

#

also make sure the dlls are not using .net 9 because some libraries are not supported by current net version of unity 3d

#

if its C++ native then copy both x86 and x64 and assign architecture to them

analog elbow
#

It seems to be set to Any platform?

snow warren
runic lance
#

as was said before, setting the isStatic flag is irrelevant, since it's editor only

snow warren
analog elbow
#

@snow warren That appears to have worked, thanks.

snow warren
#

now when i give the gameobject[] to it it gives me an error

timber tide
#

If you're using URP you may not even need to static flag stuff

#

just ignore it for now unless you run into optimization problems

snow warren
timber tide
#

ah, ok

swift crag
snow warren
runic lance
#

paste the exception here

snow warren
#

sorry

#

its a System.NotSupported Exception

#

now i dont really know what happened wrong here

#

since its not being supported

short hazel
#

Paste the full exception, with the message and the stack trace below it

robust condor
#

Where is a good place to store references to my scenes (they are in addressables). So my scene manager can load the scenes, maybe by type instead of strings, instead of Addressables.LoadSceneAsync("level1") ...

#

Should I just create an enum?

snow warren
#

i found a cruel thing
the static batching utility combine doesnt actually combine 2 meshes
its only combines both meshes into one so that even if the position of one gameobject changes the rendered mesh stays in place

swift crag
#

it produces a new mesh

snow warren
#

yea

olive galleon
#

I asked earlier what's better to use EventHandler vs Action and I got most responses saying Action, so how would I refactor this code in order to replace the (this, EventArgs.Empty) to use Action ?

swift crag
#

an Action takes no arguments at all

#

you simply invoke it

grave frost
swift crag
#

can't you just get an AssetReference for the scene?

#

I don't use addressables very much, mind you

swift crag
grave frost
#

wait is it just public event Action<Vector2> VelocityChange;

#

oh it is lol nvm

runic lance
grave frost
#

yea but i always like to have explicit accessibility modifiers

#

thanks though!

cinder wigeon
#

good evening, I have a question about getting Visual Studio Code to recognize Unity keywords. Currently I followed a tutorial for a project setup tool, and after completion everything works great. Those scripts show keywords as expected. However, once I created my project folder and made scripts inside of that. Those scripts are not recognizing anything. Its confusing me as I have the new scripts and the old ones open at the same time in visual studio code. The old ones work and the new ones don't.
Both the old scripts and new scripts were opened first through unity interface
Any help is appreciated.

fringe plover
#

I think im terrible at math.

    private new void FixedUpdate()
    {
        base.FixedUpdate();

        if (longRenderer == null) return;
        timePassed = (SongController.instance.instSource.time - data.pos);

        if (toDisableWhenHit.activeSelf) return;

        // 30 is scaling, -1 is to make the end shorter
        longRenderer.size = new(longRenderer.size.x, ((data.lenght - (timePassed /4)) * 30) -1);
    }

data.pos is when note supposed to be hit in seconds, when data.pos is 0 (basicaly hit when song starts) all calculations are right.

But when its bigger than 0 the timePassed goes negative and wrong...

i tried fixing this all day but i have no idea what causes it.

the calculations are for long notes when player is supposed to hit note, it stops moving and longRenderer becomes shorter over time.

swift crag
cinder wigeon
fringe plover
#

When you create new project (except example ones) it doesnt create any folder but one for Scenes

#

you supposed to create them

cinder wigeon
#

the code in the "editor" folder is being picked up correctly in visual studio code and shows keywords
the code in the "scripts" folder is not showing unity keywords in visual studio code

obsidian plaza
fringe plover
#

it basicaly breaks even more

obsidian plaza
#

lol

cinder wigeon
#

any ideas on the issue I mentioned?

teal viper
eternal falconBOT
cinder wigeon
#

just confused why scripts in one location are recognizing all the unity keywords, yet scripts in other locations don't recognize anything

teal viper
cinder wigeon
#

This is an example of the scripts not being recognized

robust condor
#

Are they ever gonna get rid of the "Hold on" loading bar?

cinder wigeon
#

both are within the Assets folder

#

you can see the imports and keywords are not green and aren't recognized. Although the script does compiile and work

open veldt
#

Quick question, my delta time is not working in the first if statement and I don't know why, it kind of just lingers around the same value. The else if works fine. I'm not sure what's up with it

teal viper
cinder wigeon
fringe plover
#

check if currentStamina is > 0

teal viper
fringe plover
#

since you sau that else if runs instead every time

cinder wigeon
#

I see what you mean. The working file has the following:

#

the not working ones have this:

teal viper
eternal falconBOT
fringe plover
#

or <= in case if it goes negative

#

@open veldt

open veldt
#

Give me one second because the error is something different

Basically the else if goes up 1 every second like it's supposed to, but the if statement doesn't go down 1 every second. Both run when they're supposed to (If runs when shifting and else if runs when not shifting)

#

I'm gonna screenshot the console logs

#

the issue is deltatime being weird I think?

fringe plover
#

wait

open veldt
#

so when currentStamina is 0, it goes up by 1 every second until it's equal to baseStamina

Then this is what happens when I shift, it doesn't go down by 1 each second it's all just this

#

😭

fringe plover
#

try multiplying Time.deltaTime, and check if Time.scale is set somewhere

#

it affects it

open veldt
#

alrighty

teal viper
#

It's likely that you just have high fps, so individual logs(one per frame) wouldn't show big difference.

open veldt
#

I know it's not working because stamina should run out over 3 seconds if it were going down by one, but it doesn't, that little clip is about what EVERY printed value is because everything is around 2.99 and doesn't get lower than that

sour fulcrum
#

Feeling a little dumb here but i'm iterating through a textures pixels, how can I convert my index, width and height to a x,y position?

teal viper
open veldt
#

This log is coming from the if statement where it checks for left shift

teal viper
teal viper
sour fulcrum
#

no no as in I have an 1d array of pixels

#

i don't know how to math my way into the right x/y from my index and w/h

teal viper
cinder wigeon
sour fulcrum
#

Texture.GetPixels()

I'm looking to get an x/y of the given pixel

#

it's ordered from top left to bottom right

teal viper
fringe plover
#

when you do that, it returns Array of pixels, you can calculate position by using texture size (for example, if you use texture x size in array, it will return last pixel on first row)

teal viper
sour fulcrum
cinder wigeon
#

thanks for the help guys

fringe plover
sour fulcrum
#

No i don';t

#

thanks

sour fulcrum
#

that i was using the wrong thing

#

tyvm

teal viper
open veldt
#

Anyway fixed it

teal viper
open veldt
#

No it was, It was this statement right here 😭 PSA to all Unity devs to stand up every so often and let your brain reset lmao

teal viper
open veldt
#

Oh yeah, Clearly i need a nap lmaooo

willow relic
#

im confused im using the open xr for vr stuff but i gotit working but theres these red beams shooting off the controlers as pointers i assume but i dont wantthem there any help i ca find them as an object

compact stag
#

guys! one question, i got a simple navmesh system where it follows the player wherever it goes, however, im re-creating slenderman, how would i go about making him teleport instead of animationless walk and how would i increase his speed as the player got the pages?

robust condor
#

I am constantly having errors with namespaces in Unity, I don't get why. I have a controller in Game.UI but it can't find it

#

And I import it into using

teal viper
teal viper
robust condor
#

It seems to fixed itself when I restarted vscode, I guess adding new namespaces do not update properly

compact stag
#

it doesnt teleport DIRECTLY to the player, ykwim?

teal viper
#

Sure, just get a random position in some radius around the player.🤷‍♂️

compact stag
#

saw a code in the unity docs that gives me a nice direction towards my goal, thank you though!

#

much love

compact stag
# teal viper Sure, just get a random position in some radius around the player.🤷‍♂️

actually, kinda wanna an opinion here

how would i make slenderman go towards the player?

using UnityEngine;
using UnityEngine.AI;

public class NavigationScript : MonoBehaviour
{
    public Transform player;
    private NavMeshAgent agent;
    private Vector3 moveDirection = Vector3.zero;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void SlenderWalk() {
        moveDirection.z = 10;
    }
    void Start()
    {
        agent = GetComponent<NavMeshAgent>();
        if(PlayerMovement.numberPage == 1) {
            if(PlayerMovement.playerIsAlive == true) {
                print("working?");
                InvokeRepeating("SlenderWalk", 3.0f, 3.0f);
            }
        }
    }

    // Update is called once per frame
    void Update()
    {

    }
}

this code doesnt make slenderman move, so just wondering how i'd make him move before fixing this bug

teal viper
compact stag
#

dont i have to specify it in the code? i can just do it in the inspector tab?

compact stag
teal viper
teal viper
compact stag
#

i was reading the docs and found MoveTowards, ill try some things and be right back!

#

dont spoil the answer, let me hit my head against the wall rq

teal viper
eternal falconBOT
#

:teacher: Unity Learn ↗

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

compact stag
#

appreciate you man!

#

ill read the docs and start on this from the beginning, dont wanna get myself confused or overwhelmed

open veldt
#

You know what I'm back cuz there's one more thing I wanna fix

I'm attempting to use the new input system and if you press W and S or A and D at the same time the character stops moving
I want to avoid it stopping because when you press the controls quickly or accidentally hit the other key the character clearly stops and I imagine it'll be kind of annoying, I just want it to keep going in the direction it originally was going if the opposite key gets pressed

I'm not sure how to make it not do that because I've been looking stuff up and cant find a thing about this problem

gleaming plaza
#

Is there a way to set an object to be an instantiated prefab? because using Instantiate(prefab) creates a clone of the prefab in instead of an actual prefab in the editor, and whatever I was trying to do here doesn't seem to work

teal viper
gleaming plaza
#

I mean, I guess I could just set them manually now that I think about it

teal viper
fringe plover
eager spindle
#

we use Instantiate, a static function in GameObject

#

Instantiate(...) returns the gameobject

feral moon
#

Hey, guys! Can you help me, please? There's an error with the script and I can't solve it in any way... 😦

I downloaded the weapon addon, but there is an error on the part of the code.:

Assets\MFPS\Scripts\Player\Controller\bl_FirstPersonController.cs(149,19): error CS1061: "MouseLook" does not contain a definition for "Init", and an available "Init" extension method could not be found that accepts the first argument of the "MouseLook" type (are you missing the using directive or an assembly link?)

Assets\MFPS\Scripts\Player\Controller\bl_FirstPersonController.cs(522.53): error CS1061: 'MouseLook' it does not contain a definition for 'SetTiltAngle' and it was not possible to find an available extension method for 'SetTiltAngle' that accepts the first argument of the 'MouseLook' type (are you missing the using directive or the assembly link?)

Assets\MFPS\Scripts\Player\Controller\bl_FirstPersonController.cs(544,19): error CS1061: 'MouseLook' it does not contain a definition for 'SetTiltAngle' and there is no available extension method for 'SetTiltAngle' that accepts the first argument.

Here code of "MouseLook": https://hastebin.com/share/tucumeduge.csharp

And the code where the error occurs: https://hastebin.com/share/derapatevo.csharp

Errors: https://hastebin.com/share/rukofofora.sql

near wadi
#

you can click remove embeds to save space

burnt vapor
#

From a first glance it looks fine. Namespace is included, arguments seem correct

#

Maybe just didn't save the code?

#

Maybe you have two files that both contain MouseLook somehow?

feral moon
burnt vapor
#

What happends if you right click MouseLook and go to Go to Implementation?

feral moon
burnt vapor
#

Just wondering if you referenced te same class here

feral moon
burnt vapor
feral moon
burnt vapor
#

What do you mean addon? Is it not yours?

feral moon
burnt vapor
#

Well I can't say what is wrong when it's an addon. It might be possible it can't even compile

#

Maybe try redownloading it

#

FWIW, it all seems fine.

#

Maybe you can check if it supports your version of Unity @feral moon

#

Note that if code doesnt compile, it could delegate down as a seperate error to different code

midnight jolt
#

If I need to use gameObject.GetComponent<FetchData>() a lot in my script, should I just make a FetchData data; and

void Start()
{
  data = gameObject.GetComponent<FetchData>();
}```
in the script? Is it good practice? Or should I stick to gameObject.GetComponent....
#

Both will work, it's just I want to keep my code clean

eager spindle
midnight jolt
#

alright, thanks

midnight jolt
#

Roger that

compact stag
#

guys! a question, i got a single audio listener in my game which is the camera, but everytime my character dies my console blows up with the message "There are no audio listeners in the scene. Please ensure there is always one audio listener in the scene"

how would i go about fixing this? should i even try to fix this?

#

i assume that for game overs i shouldnt delete my character but rather only remove its movement and add a game over screen?

#

or is there a better way to do it?

short hazel
#

What I usually do is decouple the camera from the player, as in it's not on a child object. That way if I ever need to move the camera somewhere else (to make some transition for example), it's faster to edit the relevant scripts. If you have Cinemachine installed (which you should) it's even easier

short hazel
#

A package that makes working with cameras easier and adds way more features

#

Transitions, camera follows with a lot of options, coupled with the Timeline package you can make good cinematic scenes, etc.

compact stag
#

i see

#

so thats good to use when making a jumpscare correct?

short hazel
#

Maybe?

naive pawn
#

it's for camera movement in general

#

do your jumpscares involve moving the camera?

compact stag
#

thank you guys!

frail wind
#

guy can anyone explain why the Restart Game Button don't work when i click it, even tho i did everything right.

short hazel
#

The button is disabled in the Hierarchy here. Do you get the Debug.Log on line 45 printed in the console?

frail wind
#

what is it have to do with Debug.Log tho?

short hazel
#

You placed a log that should run if the code is executed. If you do not get the log, this means the function isn't being executed

#

You can use that to ensure the function is executed when you click on the button

#

If you do not get the log, then the button isn't reacting to the click

frail wind
#

ok let me check if the Debug pop up

#

god the Debug message poping up like crazy

#

380 of them

rich egret
#
    {
        if (collision.collider.CompareTag(playerTag))
        {
            if (collision.relativeVelocity.y <= 0)
            {
                TakeDamage();
            }
        }
    }```

Hey I'm trying to make it so that when a player hits an enemy from above it takes away their life
But for some reason it doesn't always work
frail wind
#

and it say "GameOverScreen Show Point
UnityEngine.Debug:Log (object)
LogicScript:Update () (at Assets/script/LogicScript.cs:22)"

rich egret
#

I know it's a problem with the collider or something.

short hazel
short hazel
#

Then the button isn't receiving the click, make sure it is enabled and that no other object is in front of the button (that can block the click event from reaching the button)

frail wind
#

maybe because of the button text

#

let me check for a bit

short hazel
#

The text is made not interactable for that purpose. Again, I can see that the button is disabled on your screenshot:

frail wind
#

and also the button work again but it won't restart the game

short hazel
#

Okay then it might be ScoreOverText that's covering the button

frail wind
#

button are clickable

#

i got the debug.log as well

short hazel
#

Good, you just have to make sure the "Game" scene exists and is added to your build settings

frail wind
short hazel
#

No you need to check that you have added it to the scene list in your build settings

#

And that the name is correct, of course

frail wind
short hazel
#

To reduce the size of your game when you build it into an executable, you need to specify yourself which scenes to include in the game. This is done from your project settings (Edit > Project settings)

frail wind
#

i know what scence is tho

#

but putting "Game" in scene is where it confuse me

short hazel
#

You do this: SceneManager.LoadScene("Game") - this tells Unity to load the scene called "Game". If you do not have a scene called "Game", nothing happens, or you get an error

frail wind
#

Ohhhh i see

short hazel
#

Your current scene is named "SampleScene", it's the default name:

#

If you wish to load that one, your code should say so

frail wind
#

i fully understand now

swift crag
#

When you build your game, Unity grabs all of the scenes listed in your build settings

#

It then figures out all of the assets that are used by anything in these scenes

feral moon
swift crag
#

That's how it decides what belongs in the built game

swift crag
short hazel
frail wind
#

thank, also you kinda unlock part of my brain

#

👍

feral moon
# swift crag I'm not sure what an "uninitialized object" would be here

Do you understand what I mean?

NullReferenceException: Object reference not set to an instance of an object
bl_WeaponBob.Movement () (at Assets/MFPS/Scripts/Weapon/Movement/bl_WeaponBob.cs:160)
bl_WeaponBob.OnFixedUpdate () (at Assets/MFPS/Scripts/Weapon/Movement/bl_WeaponBob.cs:100)
MFPS.Internal.bl_UpdateManager.FixedUpdate () (at Assets/MFPS/Scripts/Internal/General/bl_UpdateManager.cs:215)

Right?

swift crag
#

That's not an uninitialized object!

#

That's no object at all (:

feral moon
#

Where can I ask about this? 😄

swift crag
#

right here, perhaps!

feral moon
#

Really? Okay...

swift crag
#

You are trying to use a null reference on line 160 of your weapon bob script

#

Show us the code around line 160. Make sure to indicate that line, since we won't have line numbers

feral moon
swift crag
eternal falconBOT
feral moon
#

Second...

feral moon
swift crag
#

Okay, so line 160 is

#
tempWalkSpeed = motor.GetCurrentSpeed() * 0.06f * settings.WalkSpeedMultiplier;
#

Something on this line is null.

#

Check that both motor and settings are valid

#

Well, since you made it past line 158, settings is probably fine

feral moon
#

This is an addon, and if I put it on an empty project, everything is fine, but if I put it on my own project, there are errors.

burnt vapor
#

Glad that works now

swift crag
#

so, pause and scroll up to the very first error in the console

feral moon
swift crag
#

rather than throwing out the entire project, you should have a look at why the error is happening

#

You should at least check if motor is null

#

throw a Debug.Log(motor) in there

feral moon
#

Okay... I tried

feral moon
cosmic dagger
eternal falconBOT
feral moon
#

Oops... Sorry...

swift crag
#

it'll tell you if motor is currently a null reference

#

Is this code from the asset, though?

#

It looks like it's reminding you to initialize the component properly

brittle maple
#

Ok, im having a serious problem Dx , im using "rigidbody.linearVelocity" to move my player, I added the camera and it all works fine, except the fact that the player movement doesnt change no matter where im looking, I am rotating my "Player" gameObject along the Y axis but still nothing, should I be using another type of thing for moving the player or did I do something wrong?

naive pawn
#

Note: The linearVelocity is a world-space property.

brittle maple
scarlet hull
#

i want to set up ui in a pre known place at the end of this game i can turn it on and show (on the screen) how can i place it in a correct place? screen size is diffrent if i do scale 0.25x 1x and 5x

naive pawn
feral moon