#💻┃code-beginner

1 messages · Page 94 of 1

teal viper
#

Use drive D. Also, uninstall games.

steep mist
#

yep i started putting the big stuff over there

steep mist
meager gust
#

you can get like 2tb ssds for like $100 btw

#

and it is christmas time

#

wink wink

teal viper
#

Btw, I still recommend you going through C# basics/manual.
Ideally you want to understand 100% of the tutorial code by the time you finish it.

steep mist
#

rip the stuff on it

#

my rig was and still is kinda ghetto, i use a fold out dinner table for my laptop, so theres not any practical solutions for storing and using external drives other than sitting it on my lap with a long wire

#

darn gifs aren't allowed here. was gonna insert a gif of muscle man

timber tide
#

also removing older editor versions / unused projects and such since that can eat your space pretty quickly

real dome
#

possible to refer to a different light source instead of GetMainLight(); in unity 3d unlit shader graph?

#

for example a spot light

#

also im guessing that i wont be able to refer to MULTIPLE light sources would i

timber tide
real dome
#

my bad guys :C

fringe pike
#

how could i check if any keyboard key is pressed? bc if(Input.anyKeyDown) returns true if mouse is pressed aswell

remote hound
#

Hey guys, does anyone have a simple camera/wasd movement script with gravity that I could just copy into my game? Thanks, I haven't been able to find a good one after googling it for about an hour...

fringe pike
#

make one

remote hound
#

I want to, but I don't have time rn

queen adder
#

Hey guys. Quick question.

I have a prefab that spawns a "pet" when the player purchases that "pet". I can animate it to walk around and spawn at a certain place on the game view by using a spawn point.

But im trying to make it so it walk around in like a little "pen".

So i will be creating a enclosure for the pet.
So when the pet spawn i want it to freely walk around in that enclosure.

Is there a way to achieve this? I dont want it walking past the enclouse fence. So if it reaches the fence it will turn around and walk somewhere else. Like its trapped in a box and it cant go past a certain point of that box.

#

Or will i have to animate a path for each and every pet i make?

Or is there a way to make say a movement script for the pet to freely wanter around in that enclosure (box)

timber tide
#

implement yourself some roomba AI

#

if bonk, turn around

languid spire
celest flax
#

I'm trying to make my player script call a function from a script on another object. The player script doesn't know what the script is called, but it does know what it inherits from. I've been using SendMessage() to achieve this, but I'm not a fan of using strings to call functions. Is there a better way to accomplish what I'm trying to do?

timber tide
#

SendMessage is usually for lazy debugging

languid spire
#

you can use GetComponent with the base class and it will find any script which inherits from that class

timber tide
#

I wouldn't mind it too much on smaller projects, but it's a linear search through all methods and components so it can get out of control

celest flax
fringe pike
#

how could i check if any keyboard key is pressed? bc if(Input.anyKeyDown) returns true if mouse is pressed aswell

verbal dome
fringe pike
#

tysm

verbal dome
#

Maybe theres a cleaner way, but that doesnt seem too bad.

fringe pike
#

it's fine, not making a huge project

#

thank you

timber tide
#

could make your own input method with all the keycodes you want ;)

fringe pike
#

one more question

#

when i have a button and i click it i have it "selected", when i then click space it clicks it again, same with the slider, once i have selected it i can move it with "a" and "d", how can i disable that?

hasty spire
#

I was wondering how to get it to look at a TextMeshPro -Text UI file i tried to use just Text but it isnt working

languid spire
hasty spire
verbal dome
halcyon summit
#

Does anyone know why this material is returning null, despite the filepath being copied and pasted?:
Material textMaterial = new Material(Resources.Load<Material>("Assets/TextMesh Pro/Resources/Fonts & Materials/Futura Medium Test.mat"));

teal viper
#

Also, I don't think that's a valid path for loading via resources.

#

It's supposed to be relative to the resources folder.

fringe plover
#

why i cant add TMPro, i wanted to replace old text component in GameJolt API but i cant add TMP

languid spire
fringe plover
#

ofc

#

it working in other scripts

burnt vapor
#

Is this script part of an assembly definition?

fringe plover
#

idk...

burnt vapor
#

If so, add TMPro as a dependency

fringe plover
#

how?

burnt vapor
#

How do you mean you don't know? This is your project

fringe plover
#

this is GameJolt API, i wanted to replace old text component in api with TMP, i already said that

burnt vapor
#

It is part of an assembly definition, because it's part of GameJoltRuntime rather than Assembly-CSharp

#

Are you editing a library you installed? You should not do that

#

You should either request a change or find a proper implemented solution

fringe plover
#

this is plugin

burnt vapor
#

That doesn't really tell me anything

#

Show me a picture of where this file is located in your editor

eager elm
fringe plover
#

oh, thank you so much, ill try

#

it really helped, thank you!!

glossy eagle
#

Hi. Is there a way to know if an object is like to the right or to the left relative to another's object forward vector please?

#

like I could use some inverse transforms, but when I rotate the object it is taking the inverse from, the right and left are inverted. Like I would need it to be in world right and left, I don't know if I'm explaining myself😅

hard sigil
#

guys why I can't fully move my mouse up and down? maybe something with the script x y ?

queen adder
#

@glossy eagle you could compare positions, if object position.x is less than this position.x it is to the left and so on

glossy eagle
#

that wouldn't work because it is in 3D so position x being greater than the other one wouldn't always mean it is in its right relative to the forward vector, but that gave me an idea on how to do it I think, thank you so much 😄

distant mesa
#

i have a script that generates a Capsule by code, but i need to add rings to the "cylinder" part of the capsule, how do i do that? im very new to mesh generation

heady sorrel
#

So probably a really scrub question:

I have an IEnumerator that doesn't seem to function correctly, I can call it properly but it doesn't go past the "WaitForSeconds" part in my character controler state machine.

I moved the IEnumerator to the root of my state machine to make sure it doesn't get deactivated and the time should work correctly so I'm not sure why it isn't going past it.

PlayerStateMachine.cs

    public IEnumerator IJumpResetRoutine()
    {
        Debug.Log("Enter Routine");
        yield return new WaitForSeconds(0.5f);
        JumpCount = 0;
        Debug.Log("Exit Routine");
    }
}```

`PlayerJumpState`
```cs
public override void InitializeSubState()
    {
        Context.Animator.SetBool(Context.IsJumpHash, false);
        if (Context.IsJumpPress)
        {
            Context.RequireNewJumpPress = true;
        }
        Context.CurrentJumpResetRoutine = Context.StartCoroutine(Context.IJumpResetRoutine());
    }```
#

"Context" refers to variables back in the main state machine script

#

anyone know what it could be? 🤔

eager elm
heady sorrel
#

No, but I think I might have figured it out

#

I have a HandleJump that resets it on an enter state

#

but it seems my enterstate triggers after my InitializeSubState

#

so it start the routine and on the same frame setops it

fringe plover
#

i tried to make scrolling bg with tutorial, but this happens, what should i do?

#

!code

eternal falconBOT
fringe plover
#

i fixed

verbal dome
faint sluice
#

My colleagues absolutely despise use of Action feature
More specifically subscribe and unsubscribe feature...

Is there something I'm missing is it bad practice to use that?

lament ingot
#

hello, im making project with my friends. Its about simulating light in 2d(its for competition) and q of my friends is making mirrors another is making prism etc. And i have to do lens

#

but there are no tutorials for that

#

do you have any ideas how i could do it

#

for start i would like to make easiest len

#

and then other ones

gaunt ice
#

get the normal and find the refracted ray by snell law

halcyon summit
lament ingot
#

i started with thin lens

halcyon summit
teal viper
#

Then there must've been additional issue.

halcyon summit
#

So I tried:
Resources/Fonts & Materials/Futura Medium Test.mat
Fonts & Materials/Futura Medium Test.mat

teal viper
#

How do you debug it?

halcyon summit
#

if (textMaterial == null) { Debug.LogError("Material not loaded"); } else { Debug.Log("Material name: " + textMaterial.name); }

#

Directly after the Resource Load.

old gorge
#

Regarding access to various components of a GameObject, most of the time I see people grabbing those in Awake/Start using GetComponent<T>().
I usually expose a SerializeField of the component types that I link in the inspector as it seems to me that it fits the dependency inversion principle and would be more robust.

Is there a common best practice between those two ? Any shortcomings I am missing for extensively referencing components via a SerializeField ?

teal viper
halcyon summit
teal viper
languid spire
teal viper
#

file extension huh

languid spire
#

ye

halcyon summit
#

Having it relative to the Resources folder and removing the file extension worked, thanks everyone.

spare sparrow
#

Hi anywhere where i can send my script and ask for help finding my bug? i am genuinely at my wits end with this

gaunt ice
#

just ask

spare sparrow
#

Ok so i have a script that is supposed to spawn trees/flora randomly on a tilemap. It spawns them from higher y coordinates to low y coordinates to avoid tree sprites spawning on top of each other.

i have a gameObject[] of multiple tree sprites of which a random one is selected and spawned.

for some reason when i drag the same prefab into every slot in this list the spawning works fine.
But every time i try to select from a random of 3 prefabs they spawn on top of each other/ ones with lower y coordinates are sometimes spawned first.

All the prefabs are rendered in the same way and have the same pivot points. Why could this be the case?

Here my code: https://paste.ofcode.org/PzcWpnDhRVavaVZkpmU8Gq

languid spire
#

!code

eternal falconBOT
spare sparrow
#

my bad lemme just figure that out

gaunt ice
#

show the screenshot of expected result and what you get now?

#

btw i think it should be the problem of sorting order

old gorge
summer stump
# old gorge any opinions regarding this question please ?

They are essentially the same. The engine still needs to do work to link the serialized fields when runtime starts, but that IS marginally faster than using getcomponent (unless the getcomponent fails).
Drag and drop is not really dependency injection at all though

I would say there is a negligable difference between them, but I personally do GetComponent mostly because I like to code more than I like to use the inspector.

But generally drag and drop is preferred because of how easy it is, and it will not work if you do something wrong, whereas getcomponent will happily let you try something that won't work

queen adder
#

i have a small question its basicly my first bigger code that hasnt been done with a tutorial / reference and i couldnt find any solutiong or cause of this.

i wanted to create if statements that have 2 conditions instead of just one but when i want to check if they are true by == it puts it out as a mistake in VS

wintry quarry
#

you did if (Input.GetKey(KeyCode.LeftShift)) < this was the end of the if statement.
Everything you have after that is ???

queen adder
#

aah so i need another () around the entire thing to clearify it belongs to the if statement ?

wintry quarry
#

you need to not end the parentheses before the rest of your condition

#

well it depends how you look at it. Basically an if statement needs to look like this:

if (something)
{

}```
#

what you have is this:

if (something) some random extra stuff;
{

}```
#

the semicolon is wrong too^

#

the whole expression needs to go inside the ()

queen adder
#

i did what i thaught i understood and it went away i might have just explained what i ment wrong. dose this fix it ?

if ((Input.GetKey(KeyCode.LeftShift)) == true && (SprintMet > Sprintmin) == true)
{
    Running = true;
    CharackterSpeed = SprintSpeed;
}
#

it dosnt Line it with red anymore

summer stump
queen adder
#

aaah now i understand what you ment hmm now im confused why i had the extra brackets in the first place.
is there any use in having them the way they were like this (if it wasnt an Error)

if (Input.GetKey(KeyCode.LeftShift)) && SprintMet > Sprintmin

also ty for the help

#

ooo hold on no == check ? :0

wintry quarry
summer stump
wintry quarry
#

if something is true, it's true.

bool x = true;
bool isXTrue = x == true; // you COULD do this but it's useless. Why not just do:
bool isXTrue = x; // x is ALREADY a true/false (boolean) value.```
#

== true is redundant, 100% of the time

summer stump
#

Syntax of an if statement
if (this is the condition) this is the body

queen adder
fierce shuttle
# faint sluice My colleagues absolutely despise use of `Action` feature More specifically subsc...

Theres nothing really wrong with using an Action, its just one of many ways to handle events, regardless of what you use, youll still have to subscribe and unsubscribe from any event type, including a UnityEvent, in most cases, objects will have to manage when they (un)subscribe in their lifecycle (and events can have anonymous functions such as => ... or delegate { ... }, these cannot be unsubscribed easily unless the thing they subscribed to is destroyed and GC-collected before the object subscribing, AFAIK) - its often better to subscribe functions that match the event params anyway, so those functions can be unsubscribed (and easier to read imo), and you should always unsubscribe, as its possible to cause memory leaks if you manage events poorly, just as anything in programming can cause problems with poor management, though I think those are smaller problems depending on your project architecture

I would maybe ask them to elaborate, you can also ask them what alternatives/programming patterns they prefer over events, and the context in how they choose to structure code - events on their own is not a problem, but it also may not be a solution to every use case, depending on what is trying to be solved to begin with

pulsar lodge
#

PlayerController script - https://gdl.space/ewufofosac.cs
Battle Manager - https://gdl.space/oqokakaniq.cs
Enemy Battle Unit - https://gdl.space/kumovupoxu.cs
Character - https://gdl.space/demukuzami.cs
Character Base - https://gdl.space/busacifego.cs
Hey Guys! I apologize for all the code links, I am not 100% sure where my breakdown was. So this was working before when I had enemy object manually added into the scene but now i am trying to instantiate random enemies for an encounter. My attempted flow of logic is Player controller randomly generates enemies and passes it to the Battle Manager, I am getting a "Object reference not set to an instance of an object" error on line 70 in the Battle Manager when i load that script. Added screenshot of the enemy being added.

wintry quarry
#

btw this line of code seems like something that should just happen inside EnemyBattleUnit. There's no need for an external script to be doing this.

pulsar lodge
#

Sorry that should read newEnemy.name = newEnemy.GetComponent<EnemyBattleUnit>().Character.Name + "_" + i;

wintry quarry
#

except maybe for passing in the i variable

pulsar lodge
#

forgot i updated that after creating the gdl link

wintry quarry
#

although it's possible that Character is the thing that's null

#

you need to debug and find out

pulsar lodge
#

I believe it is what is null.

wintry quarry
#

well, verify that first

#

then proceed

pulsar lodge
#

i guess what i'm not understanding is why its null, since there is a get; set; in Enemy battle unit for character

wintry quarry
pulsar lodge
#

it is

wintry quarry
#

where?

#

How?

polar acorn
#

what is it assigned to

pulsar lodge
wintry quarry
#

Doesn't look like you ran Setup anywhere

polar acorn
pulsar lodge
#

yeah i think thats my issue, the data passed to setup is supposed to be this new character

#

that enemiesInBattle gets this:

#

so i guess moving that line of code will just solve it maybe

polar acorn
#

So it has no Character

pulsar lodge
#

@summer stump yeah thats also an issue i think, its being loaded on start

#

when the scene loads

summer stump
#

I reread the code and think digi is right about the issue. newEnemy doesn't have setup called on it
It is added to a different list than the one you iterate it looks like

#

The commented line would be the right list.

But if SetUpBattle is in Awake, it would be called too early anyways

wintry quarry
#

either that or stop trying to access Character right away

#

until after Setup runs

#

in fact you probably should just do that naming thing inside Setup

pulsar lodge
#

gotcha, ok i think i know what to do, I didn't catch that. this is my first game and i think i may have overreached a little for my skillset lol.

#

its definitely helping me learn alot but still feels a little overwhelming.

timid hinge
#

hi guys i have a question

#

here it suposted to appear Floor Tilemap, Wall Tilemap, Floor Tile and Wall top

the TilemapVisulaizer code its this
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;

public class TilemapVisualizer : MonoBehaviour
{
[SerializeField]
private Tilemap floorTilemap, wallTilemap;
[SerializeField]
private TileBase floorTile, wallTop;

public void PaintFloorTiles(IEnumerable<Vector2Int> floorPositions)
{
    PaintTiles(floorPositions, floorTilemap, floorTile);
}

private void PaintTiles(IEnumerable<Vector2Int> positions, Tilemap tilemap, TileBase tile)
{
    foreach (var position in positions)
    {
        PaintSingleTile(tilemap, tile, position);
    }
}

internal void PaintSingleBasicWall(Vector2Int position)
{
    PaintSingleTile(wallTilemap, wallTop, position);
}

private void PaintSingleTile(Tilemap tilemap, TileBase tile, Vector2Int position)
{
    var tilePosition = tilemap.WorldToCell((Vector3Int)position);
    tilemap.SetTile(tilePosition, tile);
}

public void Clear()
{
    floorTilemap.ClearAllTiles();
}

}

thick dew
#

I need a simple help too

timid hinge
#

from me?

#

@thick dew ?

thick dew
#

public class PauseInvoke : MonoBehaviour
{
    public static PauseInvoke Instance;
    public Canvas pauseCanvas;

    private bool canvasStateChanged = false;

    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
        }
    }

    private void Update()
    {
        if (Mathf.Approximately(Time.timeScale, 0f))
        {
            // Enable the PauseCanvas only if it hasn't been enabled before
            if (pauseCanvas != null && !canvasStateChanged)
            {
                Debug.Log("Enabling PauseCanvas");
                pauseCanvas.enabled = true;
                canvasStateChanged = true;
                Debug.Log("PauseCanvas enabled: " + pauseCanvas.enabled);
            }
        }
        else
        {
            // Disable the PauseCanvas only if it hasn't been disabled before
            if (pauseCanvas != null && canvasStateChanged)
            {
                Debug.Log("Disabling PauseCanvas");
                pauseCanvas.enabled = false;
                canvasStateChanged = false;
                Debug.Log("PauseCanvas enabled: " + pauseCanvas.enabled);
            }
        }
    }
}``` This code check if the game is paused the pauseCanvas pops up but the problem is that it prints out that pauseCanvas is enabled but the canvas is actually not enabled
#

I never faced this problem in previous unity project and its weird

timid hinge
#

@thick dew can you help me?

wintry quarry
#

I will say this is a really weird way to do this though.

thick dew
#

yea i was just trying to make it work across all scenes

wintry quarry
#

A more robust approach would be to use an event or a static property on some kind of PauseManager

#

e.g. if (PauseManager.GameIsPaused)

#

I definitely wouldn't use Update.

#

regardless though none of that is related to your problem

#

I would guess some other code is disabling the thing later, or perhaps you are referencing the wrong object entirely

wintry quarry
thick dew
#

yea it is

#

the code also correctly references the pauseCanvas

wintry quarry
#

then presumably something else is disabling it again after

#

or you're incorrect about one of your assumptions/assertions here

thick dew
#

oh why did i never thought of that

#

if the game is paused, it is before popping up pauseCanvas

eternal falconBOT
polar acorn
#

When you define multiple elements in a single line, the attribute only applies to the first

pulsar lodge
#

its weird because that sprite is being assigned

timid hinge
#

here

summer stump
timid hinge
#

it suposted to appear Floor Tilemap, Wall Tilemap, Floor Tile and Wall top

#

ok

summer stump
#

That is just a download link for anyone on mobile

#

And I aint downloading anything, sorry

timid hinge
#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;

public class TilemapVisualizer : MonoBehaviour
{
[SerializeField]
private Tilemap floorTilemap, wallTilemap;
[SerializeField]
private TileBase floorTile, wallTop;

public void PaintFloorTiles(IEnumerable<Vector2Int> floorPositions)
{
    PaintTiles(floorPositions, floorTilemap, floorTile);
}

private void PaintTiles(IEnumerable<Vector2Int> positions, Tilemap tilemap, TileBase tile)
{
    foreach (var position in positions)
    {
        PaintSingleTile(tilemap, tile, position);
    }
}

internal void PaintSingleBasicWall(Vector2Int position)
{
    PaintSingleTile(wallTilemap, wallTop, position);
}

private void PaintSingleTile(Tilemap tilemap, TileBase tile, Vector2Int position)
{
    var tilePosition = tilemap.WorldToCell((Vector3Int)position);
    tilemap.SetTile(tilePosition, tile);
}

public void Clear()
{
    floorTilemap.ClearAllTiles();
}

}

timid hinge
#

no

#

what?

wintry quarry
#

add logs
Verify your assumptions. Check if the sprites are null, etc.

summer stump
#

!code

eternal falconBOT
gaunt ice
#

maybe editor bugs, try restart editor or have you saved the script?

#

it works on my machine anyway

summer stump
eternal falconBOT
timid hinge
#

what do you mean?

polar acorn
summer stump
#

Read what the post right above you says. Then follow the instructions

junior finch
#

Is it possible to use check for a variable in a script and see if it is true in another script. like I have a bool touched in script A and I want to check if it is true in script B. Is that possible or am i going about this all wrong?

wintry quarry
pulsar lodge
#

go to one of that websites, paste your code in, and share the link to the code. It helps keep the chat clean instead of 100 lines

timid hinge
#

man?

summer stump
#

Also explain the issue when you get it

#

Oh, I think i finally understand your issue actually.
Make wallTilemap and wallTop their own lines
Not combined with floorTilemap and floorTile

timid hinge
#

here

#

ok ill try

timid hinge
#

not solved

summer stump
#

You need the SerializeField attribute over the new lines

timid hinge
#

ok

summer stump
polar acorn
#

And do you have any errors in your console

timid hinge
#

yes

timid hinge
#

i really dont understand what is going on

hasty wind
#

ik this is unity but does anyone know anything about batch coding ?

rocky canyon
#

whats the problem? i dont see where u assign the values for those variables in ur script anywher

gaunt ice
#

the serialize field is not applied to all fields

#

btw show the console?

timid hinge
#

ohhh

timid hinge
rocky canyon
#

try cs [SerializeField] private Tilemap floorTilemap, wallTilemap; [SerializeField] private TileBase floorTile, wallTop;

timid hinge
timid hinge
gaunt ice
#

there is compile error(s)

polar acorn
#

Clear the console and only compile errors will be left

queen adder
rocky canyon
#

compilation errors..

#

thats the root of the problem i would guess

timid hinge
rocky canyon
#

When there are compilation errors unity may not be able to generate the necessary metadata for serialization as a result, the fields may not appear in the inspector.

summer stump
rocky canyon
#

really?

polar acorn
# timid hinge

So, open up that file, look for the thing underlined in red and fix it

rocky canyon
#

interesting, u dont see that often with beginners

rocky canyon
summer stump
summer stump
rocky canyon
#

oh really?

#

TIL

#

so when u put them on one line it ties them together?

summer stump
timid hinge
#

thank you so much guys

#

problem solved

gaunt ice
#

no, you can put many fields at same line
i always do that

#

the attributes still work

timid hinge
#

sorry im new and i have to do PAP its a final project to my course and I didn't teach anything about programming in Unity so I don't know anything

gaunt ice
#

but be careful with Header or space since it will be applied to all fields...

timid hinge
rocky canyon
rocky canyon
#

feels similar to how markdown works

thick dew
#

.enable = true/false does not work

#

it should be like this instead: pauseCanvas.gameObject.SetActive(true);

#

this is ridiculous

timid hinge
#

is this normal?

#

the quality on game is worst

queen adder
#

because scale is 5x

ebon robin
queen adder
timid hinge
ebon robin
#

or pixel perfect

polar acorn
timid hinge
#

no

rich adder
# ebon robin

please use Links, its hard to look at code this way on DC
!code

eternal falconBOT
timid hinge
junior finch
#

can I check if target was collided by a player?

junior finch
rich adder
dusk hornet
#

https://gdl.space/emanuvoniv.cpp i have this script to open a closet but for some reason the Debug.Log("a3"); is not showing tho the main camera colide with the object and idk why

#

interactable = true; this is not working too

ebon robin
summer stump
# timid hinge look in 2

2 is also scaled. Almost always keep it at 1
You want to zoom in with the camera, not scale it up

ebon robin
#

but does it have sth to do with the speed?

rich adder
rich adder
#

Rigidbody should be moved inside FixedUpdate

ebon robin
#

so the frame rendering is an issue?

rich adder
#

thats prob why its slower

#

well apparently this one is faster

#

you said

ebon robin
#

why is it faster tho

#

delta time in chase > wander?

rich adder
#

probably a framerate issue

#

and the number that gets multiplied by time.deltaTime

#

iirc its smaller

#

so it takes longer to get to moveSpeed

ebon robin
#

i will just check the c movementDirection*Time.fixedDeltaTime*movementSpeed

#

with debug log

rich adder
#

if you debug.log both you def will get diff numbers

#

also should move both inside FixedUpdate

#

so they are both fixedDeltaTime

timid hinge
#

ok

ebon robin
#

ye fixedUpdate is more stable but the frame rate is kinda fixed

rich adder
#

physics needs consistency to work properly

timid hinge
#

i do i zoom it with the camera

ebon robin
#

I can call it game feature

queen adder
#

show at 1

kindred swallow
#

The type or namespace name 'Netcode' does not exist in the namespace 'Unity' (are you missing an assembly reference?)CS0234

#

what it mean by missing an assembly reference

queen adder
#

Billy Butcher are you using an assembly definition?

rich adder
slender nymph
languid spire
#

netcode != Netcode

queen adder
#

maybe need to put the reference in there?

timid hinge
#

guys someone said me this
"2 is also scaled. Almost always keep it at 1
You want to zoom in with the camera, not scale it up"
what can i do?

queen adder
kindred swallow
queen adder
#

yeah

kindred swallow
#

which one

slender nymph
# kindred swallow here right?

Yes. You need to reference each assembly you plan to use. Why are you even using asmdefs if you are not familiar with what assemblies are?

queen adder
#

one of them will do the trick

#

don't know which one

kindred swallow
#

all of theme will do the trick😁

ebon robin
#

what the hell

slender nymph
queen adder
kindred swallow
rich adder
ebon robin
#

the movement vector per frame

#

i guess the frame rate is around 100

#

making the speed diff so much

kindred swallow
ebon robin
#

should I go with double cuz the number is too smoll

rich adder
ebon robin
#

no remove the rgb2d

rich adder
#

oki

#

so you put both on FixedUpdate now?

ebon robin
#

nah i put myself to sleep now. Its 3 am and i am gonna call it a game feature

rich adder
ebon robin
#

thanks for the help anyways

summer stump
rocky canyon
#

what this mean?

eternal needle
tribal minnow
#

hello

#

i need help with changing scenes in relay

rocky canyon
tribal minnow
#

whenever i switch to different scene and then go back to the first scene the relay just stops

rocky canyon
#

u have a good setup? im not familiar with relay or w/e but wouldn't u need to keep the logic in a scene that u always keep open?

#

persistence

#

ooor. initializing it when scene changes, idk tbh, maybe someone who does will chime in

#

irregardless maybe some snippets of your code/ pastebin link will help.. no ones gonna know specific's unless u share yours

rocky canyon
#

oh yea that ^

rich adder
queen adder
#

Hi, Im trying to create a sprite from a Texture2D object that I load in with this function:

public void LoadTexture(string textureLocation)
{
    Texture = Resources.Load<Texture2D>(textureLocation);
    if(Texture == null)
    {
        Texture = Resources.Load<Texture2D>("Sprites/missingsprite");
        Debug.Log("Couldnt find Texture2D at location: " + textureLocation);
    }
    
    Texture.filterMode = FilterMode.Point;
    FrameCount = Texture.width / SpriteWidth;
}

Ive Already managed to make the texture less blurry, but now it looks like this:

#

How do I fix the colors?

#

Ive managed to fix it in the editor itself by changing the compression to none, but how do I do so programatically?

#

I guess for now I could also disable the 'Compress Textures on Import' setting in preferences, but ultimately Id like to be able to do it through a script as a safeguard

wintry quarry
#

set all of the settings in the editor

#

and use Resources.Load<Sprite>?

rocky canyon
# queen adder Hi, Im trying to create a sprite from a Texture2D object that I load in with thi...
     void OnPreprocessTexture () {
        var textureImporter = assetImporter as TextureImporter;
 
        textureImporter.filterMode = FilterMode.Point;
        //textureImporter.filterMode = FilterMode.Bilinear;
        //textureImporter.filterMode = FilterMode.Trilinear;
 
        textureImporter.textureCompression = TextureImporterCompression.Uncompressed;
        //textureImporter.textureCompression = TextureImporterCompression.Compressed;
        //textureImporter.textureCompression = TextureImporterCompression.CompressedLQ;
        //textureImporter.textureCompression = TextureImporterCompression.CompressedHQ;
   
        //textureImporter.spritePixelsPerUnit = 16;
        textureImporter.spritePixelsPerUnit = 32;
        //textureImporter.spritePixelsPerUnit = 64;
    }```
bleak pasture
#

How do I know wheter to akss in here or the -general version of here ?

slender nymph
#

Just ask in here

bleak pasture
#

Despite several searchs and asking bots I can't figure out how to make an editor that will save to an external file that should be modifiable by the user and that isn't not a type of asset. I don't want that assets compiled as part of my project, just want to be able to serialize/deserialize it from the editor. I already know how to do that at runtime - but all the samples I find aren't "using UnityEditor" so I know they are not correct for editor-specific code. I can see there is a file manager available in the editor but unity musts also understand that the file isn't a random file it's the serialized version of a class in it

#

But I could also be completely wrong here and I should just accept that the "unity way" is textasset/scriptable object in the editor which get compiled as base recipes and user-modifiable recipes should only be loaded at runtime

queen adder
buoyant knot
#

Unity offers some utilities to help, like JSONUtility, to help convert some things to JSON format more easily.

#

but you're really using the standard C# File class

valid pulsar
#

in the unity input system i have an input action and have it set to generate a c# class is there a way i can get a reference to the actions in the input actions through the inspector. Cause rn i have a script that i can attach to a button thats supposed to remap a key when its clicked to the next button the user clicks but i cant find a good way to reference the action it needs to remap for.

buoyant knot
#

also if you see something called playerprefs, ignore it

#

it's a shitty unity solution for saving files

#

C#'s normal File system is the better and proper way to do it

bleak pasture
#

I was hesitating between a textasset with a json in it, an external file, and a scriptableobject. I know that a scrioptable object would track references to other instances of the same type so that is a big advantage I let go but Id rather be able to edit the gamedata outside of unity

buoyant knot
#

let me see if I can patch you something handy

bleak pasture
#

where as with a json I'll have to keep numerical ids to tracks the links between items.

buoyant knot
#

this is a class that Velvary made to use the JSON utility better

#

it will help you serializing some things that are a little harder to serialize into a JSON

#

I make simple serializable classes with the bare minimum info that I absolutely need to reconstruct everything

bleak pasture
#

thanks! Im comfortable with system.io normally in a windows app but everytime I use standard classes like this something goe s wrong in unity (last time was a wss server). SO I dunno I always feel confused and lost in unity with the serialization and wheter a standard lib like system.io will works the same or at all. I appreciate you giving me these ressources to look at. My bigegst problem is always "how to do things correctly in unity" 🙂

buoyant knot
#

unity doesn't stop it from working

#

Unity just has some additional tools to help serialize some things that are a little more obnoxious to serialize

#

but anything you could do before, you can also do in Unity

#

i hope that makes sense

#

for my case, I have scriptable objects with unique string IDs. I save a simple class with a string for the SO. SO has a field for its unique string. And when I load, I use a dictionary (string => SO) to do the reverse

leaden wagon
#

hey who can help me

#

idk wth but

#

some reason

#

when i put my code

#

and play

#

and when i go back

#

the half of the code is deleted

#

and i just started unity

wintry quarry
# leaden wagon the half of the code is deleted

You'll have to be a lot more specific, with screenshots etc. because that's not a thing that happens. Maybe you forgot to save your code? Or maybe you have your code in a Dropbox folder or something?

polar acorn
#

So even when reposting it to another channel you still couldn't get an entire thought out in a single line before hitting enter

leaden wagon
#

it didnt fix it

#

lemme show

#

thats the code

#

when i reenter

#

(aka play and then reEnter)

polar acorn
eternal falconBOT
leaden wagon
#

!code

eternal falconBOT
leaden wagon
#

do i give the url?

#

wa

bleak pasture
#

Dunno if it helps I can see what the bot said twice

leaden wagon
#

!bot

#

wrong

bleak pasture
#

Seems that you dont see it or something ebt5 ?

leaden wagon
polar acorn
#

So what is the problem

#

What is wrong with the code

leaden wagon
#

i did explain u

#

i put da code

#

full of it

#

to the cs thing

#

then save it

#

and then

#

when i play it

polar acorn
#

Full thought, then hit enter

last edge
#

question does anyone know how to fix this? i accidently turn version control on but i turned it off and how i dont know how to fix this

leaden wagon
#

i did

#

i did press enter

weary moss
#

hey real quick is there a way to mass change the name of a variable?

polar acorn
weary moss
#

like change all mentions of it

last edge
#

yeah i have 2022 version how do i change it?

polar acorn
wintry quarry
weary moss
#

in visual studio community

polar acorn
eternal falconBOT
wintry quarry
short hazel
polar acorn
weary moss
queen adder
#

why is this giving me an error? this should normally work?

wintry quarry
polar acorn
last edge
#

ty

weary moss
#

alright thx

wintry quarry
queen adder
short hazel
polar acorn
leaden wagon
#

So, i have a walking code, i putted in to the 2022 c# code and when, i press enter before saving it, and i wonder why it wont work because the player (bean) falls trough the floor, and when i go visit the code thing the most of it is gone (dont know why)

polar acorn
leaden wagon
#

BASICALY

#

ABOUT

#

80/100 of the code is gone

#

20% left of it

short hazel
#

And what does that mean

#

Can you show us?

bleak pasture
#

I think they mean the regions:

wintry quarry
leaden wagon
#

bruh lemme just show a vid

queen adder
leaden wagon
#

imma rec and then show yall

#

im new at games

bleak pasture
#

They are probably not used to regions and they think the code is gone because the #region is folded

leaden wagon
#

unity 1st time

bleak pasture
leaden wagon
#

give me 1 min

short hazel
short hazel
#

Well... you told the code editor to create one

#

Which it did

queen adder
#

yea

bleak pasture
polar acorn
short hazel
#

Pretty sure you need to use the one on line 6, which is this one instead

bleak pasture
#

if object type doesnt have a .clip property or .play method that will never works

short hazel
#

Take the hint

#

I mean it's not even a hint anymore

queen adder
#

yea i misstyped it

#

sorry guys

#

works now

bleak pasture
#

// cant wait to see what EBT5 meant

deft elbow
#

All i wanna do is move this game object to the position of the mouse in worldspace. I have the script attached to the GameObject and the GameObject in the scene. Why isn't it working?

polar acorn
#

Those can interfere with teleporting via transform

deft elbow
#

Nope its just a square sprite game object

#

with a sprite renderer

polar acorn
#

Try logging mouseWorldPos before setting the position, see what it says in the console

leaden wagon
deft elbow
#

Nothing was even printing to the console when I ran the game:/

slender nymph
#

are you sure this component is attached to an active object in the scene and is not disabled?

leaden wagon
#

edited in vegas 14

slender nymph
eternal falconBOT
leaden wagon
#

oh

#

buh

#

yep me dumbass

summer stump
polar acorn
# leaden wagon

So you took the time to add in a stale meme to your video, but you did not take the time to expand the regions and see if the code is still there

#

(it is)

bleak pasture
polar acorn
#

Put so much effort into turning your request for support into a shitpost and so little effort into typing, reading, or trying anything on your own

bleak pasture
#

No worries the same thing happened to me the first time I used c#

weary moss
#

actually what do you place inside these parenthesis? Are you just supposed to leave them empty? I know you can put something in there, but what is it

wintry quarry
polar acorn
leaden wagon
#

i just mf started C#

deft elbow
leaden wagon
#

how do u expect me to be dani

#

dani the milk drinker

polar acorn
slender nymph
polar acorn
#

There's a + box

leaden wagon
polar acorn
#

expand it

short hazel
#

I'd start by understanding the code you copy/write, a #region is pretty much something that stands out in all this code

burnt vapor
#

Don't use region blocks, simple as that

deft elbow
last edge
#

hey guys how to i change my project unity version control to off im only working on my project by myself

deft elbow
#

Because if that's the case then it's not disabled

slender nymph
summer stump
deft elbow
#

The selected Object is the one I'm having the issue with, and the script I posted earlier is the Tile Cursor Script

bleak pasture
#

If you git a project and exercise a good commit discipline you can easily revert if you break something

bleak pasture
#

personally I .gitignore graphical assets but I guess unity 2022 does that by itself now

polar acorn
eternal falconBOT
slender nymph
leaden wagon
#

thanks

#

and NOPE

deft elbow
#

Yeah the cursor is still visible after pushing the play button

slender nymph
#

that's not the same component you have attached to the object

polar acorn
#

The one that's on the object

bleak pasture
#

I see big smilies and it's gone?

deft elbow
#

thanks

hidden sun
#

hi, how can i pass gameobjects through scenes?

leaden wagon
#

bro why does this sux

#

like unity kinda sux

wintry quarry
# hidden sun hi, how can i pass gameobjects through scenes?

Whenever you unload a scene all GameObjects are destroyed in it. To save a GameObject from this you can:

short hazel
eternal falconBOT
#

:teacher: Unity Learn ↗

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

wintry quarry
#

they have nothing to do with scenes

#

to pass them around between scripts you can use them as parameters in functions, or just access a Vector field/property from a reference

spare sparrow
#

Ok so i have a script that is supposed to spawn trees/flora randomly on a tilemap. It spawns them from higher y coordinates to low y coordinates to avoid tree sprites spawning on top of each other.

i have a gameObject[] of multiple tree sprites of which a random one is selected and spawned.

for some reason when i drag the same prefab into every slot in this list the spawning works fine.
But every time i try to select from a random of 3 prefabs they spawn on top of each other/ ones with lower y coordinates are sometimes spawned first.

All the prefabs are rendered in the same way and have the same pivot points. Why could this be the case?

Here my code: https://paste.ofcode.org/PzcWpnDhRVavaVZkpmU8Gq

bleak pasture
#

you could also use a manager of some sort that you keep between scenes. The key is dontdestroyonload and getting a gameobject by name

#

But last I used uniity was unity 5 so I dont know really more than this

spare sparrow
leaden wagon
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

vapid mason
#

I have a maybe dumb question. What situation can cause the behavior that OnApplicationFocus(bool focused /* this is always false */)? I've toyed with in-editor and out-of-editor, as well as clicking on the window vs alt-tabbing. Platform is PC.

polar acorn
# leaden wagon !learn

Why do you keep repeating the bot commands instead of just reading them the first time they're linked to you

queen adder
#

@spare sparrow you could add a sorting group component to the trees, and trees that are fine could be sorted above and other trees could be sorted to lower maybe? Haven't tried

spare sparrow
leaden wagon
#

got it working butt

#

i uhh

#

the camera moves

#

but not bean

#

:(

queen adder
#

@spare sparrow yeah the render queue

#

you could even have them sort based on distance and other factors if you wanted

spare sparrow
timber tide
#

I feel like the y sorting should already hide the tree

spare sparrow
#

Couldnt I also just do that without the sorting group?

queen adder
#

yeah

spare sparrow
#

Is there anything a sorting group would improve with this approach?

timber tide
#

check if the pivots are correct on each tree

spare sparrow
#

they are the same on either sprite

timber tide
#

and are sorted from the pivot and not center

spare sparrow
#

i think that might be the issue

timber tide
#

on the spriterender itself

leaden wagon
#

man i hate developin

#

i need to go back in roblox studio coding

#

:(

#

well time to switch to unreal engine

bleak pasture
#

yeah cuz c++ is so much easier than c#...

queen adder
spare sparrow
polar acorn
timber tide
#

and they are sorted by the same group?

spare sparrow
#

wait but that shouldnt change anything since im not using a sorting group yet

spare sparrow
timber tide
#

sorting groups are for overriding sorting usually, but if all are not grouped then by default (group 0, layer 0) it's the depth of the pivot that sorts, or in the case of 2D isometric it's the higher up of the pivot on the y

leaden wagon
#

bean wont move

#

when its player

#

but camere does

queen adder
#

pog

spare sparrow
summer stump
polar acorn
bleak pasture
#

I last did unity in unity 5 and pluralsight test gaves me 6% so I dont remember almost anything 😦

leaden wagon
#

okay

timber tide
leaden wagon
#

im gonna try 1 more last time

#

unity

polar acorn
leaden wagon
bleak pasture
#

all I remember basically are the base concepts (prefabs, gameobjects, textassets, scriptable objects, components etc) but otherwise Im in a similar point as EBT5. TThat UI toolkit / ugui stuff is completely alien to me

polar acorn
leaden wagon
spare sparrow
leaden wagon
#

jeez

#

mind ur own business

timber tide
spare sparrow
#

that fixes everything

polar acorn
# leaden wagon mind ur own business

This is my business. Hard to avoid reading your messages when they take up half the vertical space of the page because you type one word at a time

queen adder
spare sparrow
#

what exactly did i just do to fix it? what is this setting?

timber tide
#

The sorting axis?

spare sparrow
#

is it just "render stuff with lower y in front"?

queen adder
#

nice!

spare sparrow
#

im just confused why it works

timber tide
#

by default is the depth that you sort by

spare sparrow
#

and since i have no depth that doesnt work?

timber tide
#

technically you do have depth since it is a 3D engine, but otherwise by default 2D you can treat z depth as another sorting group

summer stump
timber tide
#

but since want more control over sorting in isometric you compare pivots from bottom to top to sort

bleak pasture
#

For my external recipes.json I have a very early storage class [System.Serializable] public class Recipe { /* edited for brevity */ public Sprite DisplaySprite; } //class because later we will add properties so struct isnt appropriate here . Im not sure it's a good idea to store a referency to a unity type like sprite like a scriptableobject would do. WOuld it be better to store the path to a a unity asset instead of that when I load it from an editorwindow or from the game I can find the sprite for it by path instead ?

spare sparrow
#

game so pretty now, big W

queen adder
#

what's those yellow line things?

bleak pasture
#

the button is a placeholder for the car ?

paper rover
#

I have no Idea how to convert a shader into URP compatible, is anyone able to help me?

rare basin
#

this is a code related channel

broken jay
#

hello guys, im new in unity and im doing a 2d game however im having a problem that i cant resolve for 2 days ahah. So i made a fov in my enemy with the transform, it has a mesh filter, mesh renderer a material and a script and attached it to a variable in my enemy object script. The fov(field of view) is visible however its behind the tilemap and i dont know why, i tried to change the ordering layer in runtime it did not work. Its visible outside the tilemap but not visible inside, if anyone can help me pls send msg or smth

timber tide
#

probably want to correct your shader from crashing first

broken jay
#

that pink thing its my fov, i want it to be visible

frosty hound
#

Have you tried adjusting the z-axis position of the mesh?

wintry quarry
bleak pasture
#

that was a reply to Osteel

frosty hound
#

I haven't really worked with mesh and sprites simultaneously, so I don't know which is actually the correct approach 🫣

weary moss
#

how can i change the Instantiated object between two gameobjects not randomly?

polar acorn
weary moss
bleak pasture
#

I might need it myself for my rpg fief simulator game Im making when I draw a random map from the land use stats for a fief . Not an rpg I swear it's not an rpg if you send the adventurers to a dungeon instead of controlling them right? 😦 😢

#

so very interested in the discussion

polar acorn
weary moss
#

but like, a variable in the place of the object, that can choose between two gameobjects

weary moss
#

what variable can do that

polar acorn
weary moss
#

and then i do something like:

gameobject = objectone;
Instantiate(gameobject, new Vector3(transform.position.x, -2, transform.position.z), transform.rotation);

?

polar acorn
#

If you already have a variable objectone use that

weary moss
#

i have two variables for different objects

polar acorn
weary moss
#

i don't want to do that because the two variables were just and example, i have a bunch of them and im managing instantiating them by coroutines, i don't want to do a coroutine for each one for the sake of efficiency, so i want a way to have only one coroutine wich has an instantiate command that can be altered

polar acorn
weary moss
#

In the code, for each if/else it will toggle this variable

polar acorn
weary moss
#

yes

polar acorn
#

That wasn't a question that was the answer

#

You have conditions you want to check to decide which one to use

#

so check them

weary moss
#

i'm using coroutines mainly because of the yield return new waitforseconds() function, because there is a series of delays in the spawning process, by doing it directly in the if/else, the coroutine will be useless

#

at least i believe

polar acorn
weary moss
#

i will try doing a boolean brb

polar acorn
#

Whats this about a boolean

#

Pass in the object

weary moss
#

is pass a coding term or are you telling me to put the object variables onto the coroutine?

polar acorn
#

I am saying make your coroutine take in the object as a parameter

#

and pass that object to the coroutine when you start it

weary moss
#

i got it now

#

thanks dude

#

also thanks for the patience

pulsar lodge
#

https://gdl.space/tucawunozu.cs Hey guys, I am trying to figure out a way of preventing this object from duplicating, It is attached to my overworld scene, and will move from scene to scene with me, however when i return back to the overworld lines 31-35 are not executing, Could you think of a better way of looking for this? I would have thought this would have sufficed but it appears not.

north kiln
#

instance could never be this

#

because Awake is only called once

pulsar lodge
#

is awake not called everytime this object is loaded?

north kiln
#

Objects are only loaded once each

pulsar lodge
#

That is not what is happening.

north kiln
#

Different loads are different instances

#

They are different objects

#

Different "this"

pulsar lodge
#

gotcha

north kiln
#

It should just be else { Destroy(gameObject); return; }

rocky gale
#

If (human.needToPoo && human.atHome)
{
human.transform.position = Vector3.MoveToPosition(bathroom.transform.position.x, human.transform.position.y, bathroom.transform.position.z);
human.needToPoo = false;
} else if(human.needToPoo && !human.atHome)
{
human.poopInPants;
human.needtoPoo = false;
}

north kiln
#

That certainly is some shit code

rocky gale
#

Yes ik

#

Thank you

north kiln
#

Perhaps keep it to yourself next time if you don't have a question

polar acorn
rocky gale
#

Mb I just wanted to share this deep philosophy with other fellow earthlings

pulsar lodge
quick ruin
#

Hey my OnTriggerEnter on a hitbox is not working when I add a Force.Impulse that is too strong on the bullet. Is there any fix besides lowering the force?

rare basin
#

you can change the rigibody's collision detection mode

#

to Continuous for example

eternal needle
sturdy cove
#

I'm trying to get this OnDrop method to update my playercards array when I drop a card onto their spot. For some reason it is not updating in the inspector, any ideas?

harsh owl
#

im trying to set a certain "hover height" the car should be fixed at. currently the car sticks to the floor and rotates towards the racetrack, but it slowly goes down and doesnt stay at one height. does anyone know how i can fix that=?

blissful yarrow
#

Hello I'm new to 3d where can i find the "pixel light count" ??? I can't find it on Project Settings > Quality.

harsh owl
slender nymph
#

!code

eternal falconBOT
slender nymph
#

well you're not doing anything at all to keep it at a fixed height so it's no wonder it's not staying at a fixed height

harsh owl
#

i was trying diefferent things which all didnt end up how i wanted

slender nymph
#

you can grab the normal from your raycast hit, multiply it by the hoverheight and that will be the direction and distance from the ground your object should be at

harsh owl
#

and how do i fix or keep it on about that distance

#

just pushing the ridigbody down?

slender nymph
#

well if you know that is the direction and distance from the ground your object needs to be at, then put the object at the ground's position + that direction

rain crow
#

Hello,

I'm trying to use Unity's "Player Input Manager" component, and I have it set to Join players when a button is pressed. I put my player prefab in there.

But when I spawn a player with the keyboard, and another with the Controller, both players are being controlled by both inputs.

Here's my script in case it's needed

https://pastebin.com/kwxN6tw3

slender nymph
#

each of those spawned objects may have a different instance of your PlayerControls class, but they both use the same exact input bindings because you aren't doing anything at all to differentiate them

#

perhaps you want to check the docs pinned in #🖱️┃input-system for some information on how to set up local multiplayer input

rain crow
#

I see, thank you for your assistance

slender nymph
#

are you using TextMeshPro or the legacy Text?

#

also this is a code channel

violet creek
#

Textmesh pro, also sorry for posting here I didn't know which one to use :3

slender nymph
#

you can also use id:browse to find a relevant channel

violet creek
#

Oh thank you 🙂

clear seal
#

can someone tell me pls what does the color pink mean and why is there an if but green?

gaunt ice
#

They are two different things

#

So two different colors

#

Btw you can change the color by some plugin in vs

clear seal
slender nymph
#

remove the Unity.VisualScripting using directive

#

there is a type called If in that namespace but you don't need anything from it

clear seal
#

so i delete using Unity.VisualScripting; ?

slender nymph
#

yes, that's what remove the Unity.VisualScripting using directive means

clear seal
#

ok

#

um it corrected it to this

slender nymph
#

then it sounds like your code is not inside of a method

clear seal
#

it also consider the ifas a function

slender nymph
#

huh?

clear seal
slender nymph
#

stop writing code outside of methods

clear seal
slender nymph
#

yes that is not inside of any method

#

the only method in that class ends on line 18

clear seal
#

so basiclly i cant use a condition outside of a method?

slender nymph
#

correct. how would that even work?

gaunt ice
#

Cs is not python

slender nymph
#

you cannot write any code outside of a method that isn't a member declaration (variable, property, method, type)

clear seal
#

😭

slender nymph
#

if you are not familiar with writing c# code, then start with the beginner courses pinned in this channel

clear seal
#

ok

#

but i am in part of a group project

#

usin c#

slender nymph
#

even more reason to learn the basics if you do not understand them

clear seal
#

i do

#

but half lol

slender nymph
#

the basic syntax of the language is literally the absolute beginning of what you need to learn

waxen adder
#

Is there some way to get multiple outputs from a function?

With my old unrealscript knowledge, I know that you could do something like this when building a function:

function bool FunctionName(int requiredInt, out int desiredOutput)

this function would return a bool, but would also provide "desiredOutput" to the function caller if they had that second parameter
caller:

myBool = FunctionName(funnyInt, someIntIWant);

Is there something similar in c#?

gaunt ice
#

out or ref or pointer

slender nymph
waxen adder
#

Ah, ok

static cedar
waxen adder
#

I'll probably use out. I've seen tuples tossed around here and there when modding games and haven't really figured out what they are

static cedar
slender nymph
#

they can be convenient, though i generally prefer just creating a small struct if i want to actually return multiple points of data

static cedar
static cedar
low perch
#

is there a way to get every scriptable object created of a scriptable object class

timber tide
#

Look into AssetDatabase methods

nimble scaffold
#

I want to do animation on key press.. can anyone tell me how? (Like w key for run animation)

timber tide
#

you can just play clips directly

#

you need an animation controller

frosty hound
#

Use a Boolean parameter in your animator and flag it true when your key is pressed

However, if you're in 3D, you should be using a blend tree that is driven by something like speed.

nimble scaffold
#

Umm.. for it do I need to write a script?

frosty hound
#

Always

nimble scaffold
#

Where to attach

frosty hound
#

Doesn't matter, as long as you create a reference to your animator.

nimble scaffold
#

May I send the script here

#

Actually I wrote the script long ago

timber tide
#

Should just try this series

nimble scaffold
#

I'm in 3d bro

timber tide
#

shows the blend tree too

#

Ah, well the logic still applies but probably a 3D animator tutorial around

nimble scaffold
#
using UnityEngine;

public class AnimationController : MonoBehaviour
{
    private Animator animator;

    void Start()
    {
        
        animator = GetComponent<Animator>();
    }

    void Update()
    {
        
        if (Input.GetKeyDown(KeyCode.W))
        {
           
            animator.SetBool("IsRunning", true);
        }

       
        if (Input.GetKeyUp(KeyCode.W))
        {
            animator.SetBool("IsRunning", false);
        }
    }
}
#

I tried but not worked

frosty hound
#

In what way?

nimble scaffold
#

But no log errors also

ivory bobcat
#

What happens and what doesn't?

nimble scaffold
#

Nothing happens

#

The charecter remains in rest

ivory bobcat
#

Does the bool get set to true and false?

nimble scaffold
#

Yeah

#

To true

#

@ivory bobcat can u guide me step by step to do animation on key press

frosty hound
#

Did you actually set the parameter on the transition to your running animation state?

nimble scaffold
#

Yeah

dawn rampart
#

it says I dont have a reference but i do?

frosty hound
#

You don't, if it's saying that.

#

Make sure you don't have multiple scripts for example.

dawn rampart
#

no erros

#

but it sats there is one there

frosty hound
#

NRE won't show as an error in your code

dawn rampart
#

it says its missing player stats manager

ivory bobcat
timber tide
#

ah, may need to update the prefab. Actually, if it's already on the scene and you're using that one exactly it wouldnt matter now that I think about it

ivory bobcat
dawn rampart
#

mb

ivory bobcat
#

Something on line 56 is null

dawn rampart
#

yeah the error says its the player stat manager

ivory bobcat
#

The error shouldn't say what but definitely something on that line

#

Likely that would be it though

dawn rampart
#

it sazs it doesnt have it but it does

ivory bobcat
#

Try logging the variable

ivory bobcat
timber tide
#

oh, it's networking too. Just do yourself a favor and update the prefab

timber tide
#

probably spawning a player manager with the last prefab instance

dawn rampart
#

the screenshot is the prefab

timber tide
#

the green + means it's not part of the prefab yet until you update it

#

what you have on the current gameobject is unique to it

dawn rampart
#

how do i update it?

timber tide
#

in the inspector panel at the top. I believe it's called override

dawn rampart
timber tide
#

May need to make another prefab and reference the model there

dawn rampart
#

this is the player

#

plus i shouldnt have to do that

timber tide
#

If you spawn another instance of player here, you're not getting those same scripts

slender nymph
#

nah, it looks like they are editing the prefab. it's just that the prefab includes a model prefab too and these objects are attached to that. but you cannot apply these overrides to a model prefab even though (annoyingly) the icon is there

dawn rampart
#

this is when it is spanwed

#

so thez are on when it is spawnede

slender nymph
#

there are 4 separate objects that could be null on line 56, you should either log them or use breakpoints to find out whihc are null

#

actually there are 3 not 4 because one of those objects is not null on a previous line

ivory bobcat
slender nymph
#

why not just Debug.Break instead of isPaused

ivory bobcat
dawn rampart
ivory bobcat
dawn rampart
#

the player

#

yeah

ivory bobcat
#

Was it highlighted yellow?

dawn rampart
#

yeah

ivory bobcat
#

The field should be empty if exposed in the inspector

dawn rampart
#

i fixed something

#

only one error

ivory bobcat
#

Try cs Debug.Log($"The Player Stats Manager: {playerStatsManager}", this);

#

Select the log after it shows

#

Something in the scene will become highlighted yellow

#

Check if the field is None

dawn rampart
#

it hilights the player

ivory bobcat
#

Check the inspector

#

Look at the playerStatsManager field

dawn rampart
ivory bobcat
#

The field isn't exposed

#

The reference is null

slender nymph
#

where are you actually assigning to your playerStatsManager variable?

dawn rampart
#

i think thats why

ivory bobcat
#

You can't use it unless you've assigned it something

dawn rampart
slender nymph
#

whenever you see something is null, that should always be the first thing you check for

dawn rampart
#

I always forget to call a function in update or assign a variabl in onAwake so i should be used to that by now

#

Thanks

queen adder
#

I'm confused, using netcode for gameobjects, calling a serverRpc function but it errors on the client machine and just says only the server can spawn network objects but i though a serverRpc is run on the server/host [ServerRpc] void spawnPlayerManagerServerRpc(ulong clientID) { GameObject playerManager = Instantiate((GameObject)Resources.Load("PhotonPrefabs/PlayerManager"), Vector3.zero, Quaternion.identity); playerManager.GetComponent<NetworkObject>().SpawnWithOwnership(clientID); }

slender nymph
wide crown
#

Hey everyone! I'm new to Unity and studying how Unity works!

#

I was trying to make my character move and this is my code:
public class NewMovement : MonoBehaviour
{
public float Move;
public float Speed = 10f;
public float jump = 100f;
private Rigidbody2D rb;

void Start()
{
    rb = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
    Move = Input.GetAxis("Horizontal");
    rb.velocity = new Vector2(Move * Speed, rb.velocity.y);
    if (Input.GetButtonDown("Jump"))
    {
        rb.AddForce(new Vector2(rb.velocity.x, jump * 10));
    }
}
private void FixedUpdate()
{
   

}

}

#

the problem is my character keep sliding if I try to move both direction

nimble scaffold
#

!code

eternal falconBOT
nimble scaffold
#

Use charecter controller

wide crown
wide crown
nimble scaffold
#

Just try it

#

Go to inspector and click add component and serach for charecter controller

wide crown
nimble scaffold
#

@wide crown u can use charecter controller instead of basic rigidbody

#

It's much effective

#

And did it worked?

wide crown
#

I'm trying to figure out how to use it!

#

damn, it is way more ez

nimble scaffold
#

Just attach that component and attach this script

using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public float moveSpeed = 5f;
    public float jumpForce = 10f;
    public float gravity = -9.81f;
    public Transform groundCheck;
    public float groundDistance = 0.4f;

    private CharacterController controller;
    private Vector3 velocity;
    private bool isGrounded;

    void Start()
    {
        controller = GetComponent<CharacterController>();
    }

    void Update()
    {
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, ~0); // Checking all layers

        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -2f; // Reset gravity when grounded to prevent accumulating downward force
        }

        float horizontal = Input.GetAxis("Horizontal");
        float vertical = Input.GetAxis("Vertical");
        Vector3 move = transform.right * horizontal + transform.forward * vertical;

        controller.Move(move * moveSpeed * Time.deltaTime);

        if (Input.GetButtonDown("Jump") && isGrounded)
        {
            velocity.y = Mathf.Sqrt(jumpForce * -2f * gravity);
        }

        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);
    }
}
#

Now I have given comments also

wide crown
#

there're a lot of of things to catch up tho

nimble scaffold
#

Yeah

verbal dome
#

Or just fix your rigidbody controller

nimble scaffold
#

And did it worked??

#

@wide crown

verbal dome
#

@nimble scaffold They are using Rigidbody2D so you cant swap CharacterController for it..

wide crown
#

yes it did!

nimble scaffold
#

I knew it

#

Thanks

wide crown
#

no, Thanks!

nimble scaffold
#

For sparing your time with me

wide crown
#

I did try to use the new input system but it was complicated

nimble scaffold
#

Bye @wide crown

wide crown
verbal dome
#

How does CharacterController work in your 2D game?

#

Are all your colliders 3D?

woven crater
#

why this medthod crash my game?

nimble scaffold
#

So finally tell did charecter controller worked?

wide crown
verbal dome
teal viper
woven crater
#

freeze

nimble scaffold
wide crown
teal viper
verbal dome
woven crater
#

its because of lerp?

wide crown
#

so I have to figure out how to fix my code then

nimble scaffold
#

But it did work right?

teal viper
wide crown
woven crater
#

i set my rate to 0.01

teal viper
# woven crater i set my rate to 0.01

Well, then do the math. Theoretically, your transform scale would never get to the target.
Also, I don't see a point in a loop like that at all. It would be the same as just setting the scale to the target value.

woven crater
#

i want to make it shrinking over time

verbal dome
wide crown
wide crown
teal viper
woven crater
#

oh right i see now

verbal dome
#

Looks like you are just using "Horizontal" axis directly so there is not much that you could do wrong

wide crown
#

letme show u

verbal dome
#

Send mp4

wide crown
#

understood

verbal dome
#

Mkv does not embed

wide crown