#💻┃code-beginner

1 messages · Page 476 of 1

humble summit
#

yes, the sarcasm is quite helpful

slender nymph
#

you are the one who insisted that the documentation was wrong even though it was really your code that was wrong

languid spire
#

even though the error message was very, very clear

queen adder
#

I think this has something to do with it being in update rather than fixed update and/or something about it not being executed gradually over time

slender nymph
#

speed = Mathf.Lerp(player.velocity.x, topspeed, rate);
this line is pointless because you are assigning to the local variable named speed which you never use after this line

#

or rather, you never use it for anything other than displaying it

#

also for future reference, when using a site like pastebin where there's no syntax highlighting by default, please have the courtesy of selecting the correct language so that there is syntax highlighting

queen adder
#

ok

rare hawk
queen adder
rare hawk
# queen adder so your suggesting that its because it IS in Update rather than fixed update?

I'm looking at your code now, but I can say with certainty you should move the physics stuff to FixedUpdate. Also see this article by Unity themselves: https://learn.unity.com/tutorial/update-and-fixedupdate

Also, I would recommend using clearer names. Calling your Rigidbody2D "player" is somewhat confusing, as often the player is the entire GameObject, not just the Rigidbody2D.

Unity Learn

How to effect changes every frame with the Update and FixedUpdate functions, and their differences. This tutorial is included in the Beginner Scripting project. Previous: Awake and Start Next: Vector Maths

rare hawk
#

But I have to say, you have a lot of things that do nothing in your code (two separate speed variables, random variables that do nothing, etc.). Maybe look up & follow a tutorial first so you get an explanation of what everything does

lean anvil
#

i got the PlateCompleteVisual Script here to deactivate the items but it activates it in the game.

#

I want the plate to be empty when it spawns and i interact with it but some of the items are there when i interact with it when it should be empty.

#

this is the script that goes with the plate

main karma
#

guys quick question, what's the "Editor Loop"?

short hazel
# main karma guys quick question, what's the "Editor Loop"?

Everything related to updating the Editor itself. Running editor scripts, keeping the Hierarchy and Inspector windows up to date as the game runs, etc. Won't be there in a built standalone executable so this entire section can be ignored when profiling

main karma
languid spire
short hazel
#

Playing in maximized will ease off the performance hit, as it needs to visually update less Editor things

main karma
#

This means I had no problems with optimization after all, but I'll still try to change my particle simulator with the VFX graph to see if there's an improvement when I figure out how to do that

languid spire
main karma
languid spire
#

well maybe that is why the editor loop is taking up so many resources

main karma
#

basically only 1 scene works atm, and I need to fix the rest for when I build the game as rn I'm testing stuff

versed light
#

when using tuples in c# like (int,int) is it by default the value tuple type or the class type ?

#

hovering over it does not tell me if its a struct or class

short hazel
short hazel
main karma
#

ok 18% of my resources were going to particle simulators

steep rose
#

any good way of activating and deactivating a boolean that is in a raycast that activates only once?

cosmic dagger
steep rose
steep rose
cosmic dagger
cosmic dagger
steep rose
#

boolean that is in a raycast that activates only once?

#

the raycast only activates once

cosmic dagger
#

Uhh, how does the raycast activate once?

#

Wait, do you mean the method is called only once . . .

steep rose
#

it only activates when Getkeydown is true and when it is done getting invoked

#

let me get you the script

cosmic dagger
#

Do you mean the Raycast method is called?

steep rose
#

called only once, yes

#

i made it to do that

cosmic dagger
#

The bool in the raycast. Can you explain that part? I checked the Raycast method(s) real quick and didn't see any bool parameters . . .

steep rose
#

raycast1 = true; is the boolean

#

does the page not have it? should be line 95

short hazel
#

Warning line 105: hit1 will be assigned a new value even if the raycast did not hit anything!

short hazel
#

This is because when using an out parameter, it must be assigned a value inside the method before any return is reached

steep rose
#

i get that, i had it as hit2 before but as i said its broken for now

#

will fix it when the raycast1 is fixed

final pelican
#

My player won't move to my keypress all of a sudden. It was working before but it stopped now.
I haven't changed anything in the scripts and a new script I made was for something different.

north kiln
#

!code

eternal falconBOT
rich adder
final pelican
north kiln
#

Nobody can help without seeing some code

steep rose
rich adder
final pelican
rich adder
#

i dont see InputEnabled = true anywhere

north kiln
#

I do

rich adder
#

ohh wops i had a whitespace in my search 😅

north kiln
#

Check what code is running with the debugger or logging

#

and make sure errors are not disabled in the Console window

steep rose
#

is your playermanager script actually getting your input script?
playerInput = GetComponent<PlayerInput>();

final pelican
#

This is what the debug looks like for the player

rich adder
#

have to put logs in the script make sure they run

north kiln
#

Debug mode is not the debugger to be clear

steep rose
#

it half debugs, not even. put some logs in your scripts like nav said

#

afaik all it does is show private variables in the script.

final pelican
steep rose
#

Debug.log();

final pelican
#

At the end of the code right?

rich adder
#

wdym "the end of the code"

steep rose
#

no, you put them wherever the script is suppose to run

#

if that makes sense

rich adder
#

when in doubt, put it in update

novel blaze
#

guys i made a pick up tool script and everything works but the only problem is that if i press e at any location it will pick it up how do i make it so that if we press e when we're near the object it'll pick it up instead if being at the other side of the map

rich adder
final pelican
#

Seems that it isn't picking up where the player is when it starts

queen adder
#

Im confused as for something

#

Why would one even need to have ANY Variables Private when there are abilities that can make ANY of them public

rich adder
rich adder
lean anvil
hollow zenith
lean anvil
hollow zenith
#

If u look at the script which "activates visual", see if it actually does anything, since you are following a tutorial maybe this part wasn't implemented yet?

zinc aurora
#

@static wasp the variable you change on the unity is different from the variable you enter in the code

#

the variable in the code is like a start point

zinc aurora
#

then you can just tweak around it

solemn fractal
#

Hey guys.. if I create an UI button.. to find the method here as shown in the SS I always need to create the method as public? no way to create it as private and acces it here some how?

frosty hound
#

Nope

solemn fractal
#

hmm. ok thank you.

#

if the funcions I have.. as public.. they are inside my UIManager script. I need to drag the UIManager script here correct?

#

I cant find the functions doing that way. what am I doing wrong?

#

example of one of the funcions:

teal viper
solemn fractal
#

I am dragging the script it self

teal viper
#

Well, the script itself is just a script asset

solemn fractal
#

ok now its fixed

#

thank you

#

already understood what you meant

teal viper
#

It doesn't represent the class that's inside of it.

solemn fractal
#

I dragged the object now UIManager and worked

cosmic dagger
solemn fractal
#

I am trying to find a better name for it.. but I will have a dmgbutton while the game is running or in the menu of the game when you die after it

#

so INGAME its while you are playing.. and not in the menu itself

#

hahahahaha

#

I am very bad with variables names

#

I try my best.

cosmic dagger
#

i'm a bit OCD about stuff like that . . .

oak nimbus
#

how do you add a menu item to this menu. its the one that shows up when you right click a scene in the heirarchy

solemn fractal
#

and trust me I just dont name them I take some minutes to think

cosmic dagger
#

they don't have to be different names unless they're in the same script . . .

solemn fractal
#

They will be in the same script

cosmic dagger
#

oh, that's . . . different . . . 😅

solemn fractal
#

inside the UIManager basically

#

Actually now thinking .. I can have more scripts inside my UImanager object. right? maybe I should create 2 scripts

#

one for buttons inside the game while running and one for when its in the menu

cosmic dagger
#

then you can do _dmgSkillMenuButton . . .

#

oh, i would not have thought they were in the same script . . .

solemn fractal
#

you would not have 2 scripts inside UIManager object you mean?

cosmic dagger
#

i would have a different script for the in-game buttons than i would for the menu buttons . . .

solemn fractal
#

yeah that is great idea I will do that

#

With that I can have better variable names and I dont need to name them with Ingame etc

cosmic dagger
#

the in-game buttons seem tied to gameplay and don't have anything to do with a menu . . .

barren scaffold
cosmic dagger
#

all of the methods? the members from ani? the members from col? it's hard to tell which/what you are asking about . . .

barren scaffold
# cosmic dagger what is supposed to show up?

states() is a local method, and is yellow.
The other methods are from other scripts or the class it is inheriting from, and they show up as white.
When mousing over the states() method, it shows its location and other info.

Main thing is I just want to be able to visually see the methods easier rather than in white.

cosmic dagger
eternal falconBOT
barren scaffold
cosmic dagger
shy nebula
#

i need help,
when i try to build my project i get this error (Assets\NavMeshComponents\Scripts\CollectTilemapSourcesCache2d.cs(30,68): error CS0426: The type name 'SyncTile' does not exist in the type 'Tilemap')

static wasp
#

someone help, my collisions arent working

    void OnCollisionStay(Collision collision)
    {
        if ((Physics.Raycast(transform.position, Vector2.down, out hit, 1.05f ) == true) && is_grounded == false)
        {
            is_grounded = true;
        }
        else
        {
            is_grounded = false;
        }
        print(is_grounded);
    }
#

nothing is being printed

blazing haven
#

Lerp Movement + Input

static wasp
#

the collision now works, but

#

this doesn't work when i make Physics 2D

north kiln
#

!docs look at the API docs for that method and make sure you use it properly

eternal falconBOT
ivory flare
#

help the ai i coded (without ml agents ) wont stand up properly i let it train for hours, and the problem seems to be with the old neural network
https://paste.ofcode.org/hKy3L3WgxNzuX6AsK6xabJ
someone please help me ive been trying to figure out why it wont work for 24 hours 😢
i just want to sleep😭 i told my self oh ya its a quick fix ill sleep when its fixed, but it i never got it fixed, so please please help me

clever idol
static wasp
clever idol
#

Oh ye mb

undone harbor
#

Were you able to find an answer?

static wasp
#

is there a way to increase the gravity of an object?

#

like i want the object to fall fast

lapis frigate
#

hey, when I tried to acsess the player by this line of code I got this error, I think its because the player is a prefab and not a game object, so is there another way to acsess a prefab or this is the way but my code is wrong?

deft grail
#

and does it have the Unit component

lapis frigate
#

it does have a unit componetn

#

but its a prefab

#

does a prefab counts as a game object?

deft grail
#

unless its a prefab IN the scene

#

which that works too

lapis frigate
#

it does in the scene when the game start

deft grail
lapis frigate
#

and like i load it in the scene and the game start

stone pilot
#

I just had a qestion

#

Is there a way I can put this

#

resolution that i use in the editor which is 800 x 600

#

to the build

#

so I can have the pixelated look ?

deft grail
eternal needle
eternal needle
lapis frigate
#

I dont know what I can debug though

#

its just one line

deft grail
eternal needle
#

id honestly change this whole code up though. pass in a reference to the Unit when calling this method and now suddenly you have items that work with any character, its more performant, and wont be completely fragile.

lapis frigate
#

so I had to change it in the code

deft grail
lapis frigate
#

I guess so

static wasp
#

you could name it names like player, camera, player_collision, etc. so unity doesn't get confused

lapis frigate
#

allright thank you for the tip

eternal needle
#

that only applies to if you're naming a class. they were naming a game object

static wasp
eternal needle
eternal needle
static wasp
#

like this situation

static wasp
eternal needle
#

i feel you're confused on what a variable or class name is, in relation to them having a string.

#

and the tip gave them now misinformation

tawny quarry
#

i have a question is verry hard for me to resolve it my player don't take any damage i give more information in vocal

static wasp
teal viper
tawny quarry
cosmic dagger
#

If you press 'H', does the player take damage?

cosmic dagger
#

Then check that the player and enemy colliders are set up correctly . . .

teal viper
tawny quarry
languid spire
jaunty obsidian
#

In void Shoot it gives me error

languid spire
#

please use a paste site to post !code

eternal falconBOT
languid spire
languid spire
plain narwhal
#

Hello, I am making this game in which these red squares will follow around the white triangle (player)

#

here is what I'm using for the enemy follow script

#

I want to create a prefab of the enemy, but if I bring the prefab in, I have to manually assign the reference of the player to every prefab

#

any way I can directly reference the player in the code?

languid spire
#

normally you would assign that at the point you instantiate your enemy or you could have a singleton which holds the reference to the player

#

also please do not post screenshots of code

plain narwhal
#

sorry

jaunty obsidian
languid spire
jaunty obsidian
#

i will send a video

languid spire
#

no. Again irrelevant, read what I wrote

#

and if you don't know the basics of Unity why are you doing multi player?

languid spire
#

then you should know how to set a refererence in an inspector

jaunty obsidian
#

i know

#

i made this in singleplayer it worked but in fusion it isnt

languid spire
#

irrelevant. The error message is perfectly clear. firePoint has not been set in the inspector

jaunty obsidian
#

i have changed the error code to Runner.Spawn(bulletPreFab, new Vector3(0, 0, 0), Quaternion.identity);

#

it still give that error

#

its because bullet

languid spire
#

if it was bulletPrefab the previous line would throw an error

jaunty obsidian
#

here s player script

#

btw bullet has its own Rigidbody2D

languid spire
#
 bulletrb = bulletPreFab.GetComponent<Rigidbody2D>();
        Runner.Spawn(bulletPreFab, firePoint.position, firePoint.rotation); //In here unity says 'Object referance not set to an instance of an object'

first line throws error if bulletPrefab is null

jaunty obsidian
#

but bulletrb is bulletPreFab's Rigidbody2D and bulletprefab has rigidbody2d

languid spire
#

but if bulletPrefab is null then there is no component to get. Nor an object to get one on

jaunty obsidian
languid spire
#

Ok, so possible multiple Player Controllers. Debug your code to see exactly what is happening and where

jaunty obsidian
#

i will try

gloomy bison
#

Will check it out when i get home

stone pilot
#

this is what happens

    {
        anim.SetTrigger("takeOf");

        isDragging = false;
        line.enabled = false;

        Vector3 startPos = line.GetPosition(0);
        Vector3 currentPos = line.GetPosition(1);

        Vector3 distance = currentPos - startPos;
        Vector3 finalForce = distance * forceToAdd;

        rb.AddForce(-finalForce, ForceMode2D.Impulse);

        cameraShake.StartShake();
    }````
#

I call the trigger in the drag end

#
    {
        if(Input.GetMouseButtonDown(0) && !isDragging && isGrounded())
        {
            DragStart();
        }

        if(isDragging)
        {
            Drag();
        }

        if(Input.GetMouseButtonUp(0) && isDragging)
        {
            DragEnd();
        }

        if(isGrounded())
        {
            anim.SetBool("isJumping", false);
        }
        else
        {
            anim.SetBool("isJumping", true);
        }
    }```
#

and then i set is jumping false if is grounded

#

why isnt it working?

languid spire
#

well that looks like your if isGrounded code will override the DragEnd code

stone pilot
#

uhhh I dont get it, well if you need the whole script I'll share

tight latch
#

so i have this script which has movement and jump but when the ground check is changed from 0 to say 1 the gravity becomes so slow why is nthat

languid spire
tight latch
#

steve may u help me also?

languid spire
eternal falconBOT
tight latch
#

dw then thx

silver basin
#

Does anyone know how to run code as soon as the object that the script is on spawns?

short hazel
#

Put the code in void Awake() on a script attached to the object.

snow warren
#

Hello
I am having a grave trouble with Unity

#

it is about Unity Transport

clever idol
#

i f-ed up i excedently changed the name of a kinda importend script and now nothing works and changed it back but it still doesnt work... HELLP

snow warren
#

normally unity transport doesnt allow variable string arrays to the network
it uses fixed strings

#

i bypassed that using this code here

#
public class NetLoader : NetMessage
{
    public int length;
    public NativeArray<int> LogLengthArray;
    public NativeArray<NativeArray<byte>> ByteArrayArray;


    public string[] RecievedPaths;

    public NetLoader()
    {
        Code = OpCode.LOAD_FILE;
    }
    public NetLoader(DataStreamReader stream)
    {
        Code = OpCode.LOAD_FILE;

        DeSerialize(stream);
    }
    public NetLoader(string[] log)
    {
        Code = OpCode.LOAD_FILE;
        length = log.Length;
        LogLengthArray = new NativeArray<int>(log.Length, Allocator.Persistent);
        ByteArrayArray = new NativeArray<NativeArray<byte>>(log.Length, Allocator.Persistent);

        for (int i = 0; i < log.Length; i++)
        {
            byte[] dat = Encoding.ASCII.GetBytes(log[i]);
            ByteArrayArray[i] = new NativeArray<byte>(dat.Length, Allocator.Persistent);
            ByteArrayArray[i].CopyFrom(dat);
            LogLengthArray[i] = dat.Length;
        }
    }
    public override void Serialize(ref DataStreamWriter streamWriter)
    {
        streamWriter.WriteUInt((uint)Code);
        streamWriter.WriteInt(length);
        for(int i = 0; i < length; i++)
        {
            streamWriter.WriteInt(LogLengthArray[i]);
            streamWriter.WriteBytes(ByteArrayArray[i]);
        }
    }
    public override void DeSerialize(DataStreamReader streamReader)
    {
        length = streamReader.ReadInt();
        LogLengthArray = new NativeArray<int>(length, Allocator.Persistent);
        ByteArrayArray = new NativeArray<NativeArray<byte>>(length, Allocator.Persistent);

        RecievedPaths = new string[length];

        for (int i = 0; i < length; i++)
        {
            LogLengthArray[i] = streamReader.ReadInt();
            ByteArrayArray[i] = new NativeArray<byte>(LogLengthArray[i],Allocator.Persistent);
            streamReader.ReadBytes(ByteArrayArray[i]);
            byte[] dat = new byte[LogLengthArray[i]];
            ByteArrayArray[i].CopyTo(dat);

            string RecievedLog = Encoding.ASCII.GetString(dat);

            RecievedPaths[i] = RecievedLog;
        }
    }
}```
short hazel
snow warren
#

it allows me send string[] of any length and size to the client

#

but whenever i try to send more than 14 strings in the array
the data is not received

clever idol
short hazel
#

There are two class CharacterController2D in your project

#

Deleting one will fix all the errors instantly

clever idol
snow warren
short hazel
#

Please have some patience

snow warren
#

sorry

short hazel
#

It doesn't seem like a beginner code issue, networking stuff should go in the #archived-networking channel as well

snow warren
#

ok

jaunty bay
#

literally what i only did is change this: (line 22-23)

        playerSpawn = spawnHandler.spawnTransform;```
to this: (line 22) on the start()

``` transform.position = spawnHandler.spawnTransform.position;

and every time i made that change, it just made that one line error. anyone knows why???

weak cedar
#

spawnHandler is null

hallow apex
#

What's at line 35?

jaunty bay
#

rb.velocity = movementInput * moveSpeed; //overall movement

short hazel
#

The exception indeed occurs on line 35:

(at Assets/Scripts/PlayerMovement.cs:35)

jaunty bay
#

yea, and i never touch that line

#

then it made the error

hallow apex
#

What's rb?

short hazel
#

rb did not have a value (it was null). You cannot access .velocity on null, so this error is thrown

jaunty bay
#

this happens other time as well, where i change something at the script, that one line gets problem as well

#

rb = GetComponent<Rigidbody2D>();

#

private Rigidbody2D rb;

short hazel
#

The object this script is attached to does not have a Rigidbody2D on it.

jaunty bay
#

but it does, n thats what im confused at

short hazel
#

Then you have another copy of this script on another object

#

And that's the one throwing

#

Make sure you didn't add it by accident

jaunty bay
#

hmm lemme check\

#

nope, all clear

#

if it were happen, something else wouldve been moving other than my player tho

hallow apex
#

You need to place a breakpoint and load the rb variable

#

This could be fixed with basic debugging

short hazel
#

It's null, there's nothing to load. Either there is another script and you missed it, or you put null yourself in rb at some point

#

GetComponent finds the component on this object. Not the parent, not the children

swift elbow
short hazel
#

If you drag-dropped the Rigidbody from the Inspector, you do not need to use GetComponent in the code.

hallow apex
#

loading a variable is when a debugger captures information about any variable, whether it has an actual reference to memory, or not

short hazel
#

Well we know it's null because they're getting the NRE, not sure of why the debugger would be useful here especially if there's only one place where they assign to rb

#

One place in the code, the field might be serialized and it's the code overwriting it with null

solar torrent
#

Idk wat i did but this is frozen een if i click play

swift elbow
short hazel
#

Whole Unity Editor window is frozen?

solar torrent
#

no thr scene is fine

#

but the game is frozen

#

i can see my camera moving in the scene window

verbal dome
#

What should be happening?

solar torrent
#

i should be seeing my chraracter

verbal dome
#

Maybe you have an extra camera?

solar torrent
#

i checked i still only have 1

verbal dome
#

Type t:camera in the hierarchy search

solar torrent
#

i want to kiss you thanks bro

#

what made the camera though

jaunty bay
#
using System.Collections.Generic; // //
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerMovement : MonoBehaviour
{
    private Rigidbody2D rb;
    public float moveSpeed;
    private Vector2 movementInput;
    private SpawnHandler spawnHandler;
    
    void Start()
    {
        //Spawn location handler when entering room
        spawnHandler = FindObjectOfType<SpawnHandler>();
        if (spawnHandler == null)
        {
            Debug.LogWarning("SpawnHandler isn't referenced in " + this.name + ".");
        }

        Transform playerSpawn = transform;
        playerSpawn = spawnHandler.spawnTransform;
        

        //Rb reference
        rb = GetComponent<Rigidbody2D>();
        if (rb == null)
        {
            Debug.LogError("Rigidbody2D component missing from this game object.");
        }
    }

    void FixedUpdate()
    {
        rb.velocity = movementInput * moveSpeed;    //overall movement
    }

    private void OnMove(InputValue inputValue)  //triggers when an input happens
    {
        movementInput = inputValue.Get<Vector2>();  //gets the vector2 value of the inputValue
    }

}
verbal dome
solar torrent
#

o0o0o0o yea i did

verbal dome
#

It might import lights too

solar torrent
#

bet i found it thanks

jaunty bay
#

oh sorry

short hazel
# jaunty bay this is what i meant

Make sure all scripts are saved, clear the Console and play the game again until you get the error. Look at the new line number in the stack trace of the error

jaunty bay
#

and now,

#

it ... works???

#

i just redo all of the things i did multiple times

#

programming in a nutshell

jaunty bay
silver basin
#

How do I check static variables in the editor?

short hazel
#

You can't, they're not tied to an instance of the script (which gets created when you attach it to an object)

silver basin
languid spire
short hazel
#

They're available from the code, you can Debug.Log() them or inspect their values with the debugger

jaunty bay
#

i want to execute a function every time any scene is loaded. how can i achieve that?

languid spire
#

subscribe to onSceneLoaded

jaunty bay
#
    {
        SceneManager.sceneLoaded += OnSceneLoaded;
        Debug.Log("SceneLoad subscribed.");
    }

    private void OnDisable()
    {
        SceneManager.sceneLoaded -= OnSceneLoaded;
        Debug.Log("SceneLoad unsubscribed.");
    }

    void OnSceneLoaded(Scene scene, LoadSceneMode mode)
    {
        spawnTransform = FindSpawnLocation(spawnID);   //look for the correct spawnLocation with the corresponding spawnID
        Debug.Log("Current Spawn Location: " + spawnTransform.position);
    }
}
#

did i do anything wrong?

languid spire
#

As long as that code is DDOL it's fine

jaunty bay
#

do i need to execute it on OnEnable() ?

languid spire
#

It wont execute OnSceneLoaded for the current scene, only when you load new scenes

jaunty bay
jaunty bay
#

so im assuming my function isnt executed

languid spire
#

then your setup is wrong
you need a 'loading scene' with this code and it needs to be ddol, then you can load your game scenes

short hazel
#

Yeah currently it does:

  1. Scene is requested to load
  2. Objects in the old scene are destroyed, OnDisable runs and unsubscribes your method from the event
  3. New scene is loaded and the event is raised, without any subscribers to handle it
teal viper
# jaunty bay

It looks like it's unsubscribing immediately, so obviously it wouldn't react to any scene loaded after that.

languid spire
#

which means he completely ignored the DDOL bit

jaunty bay
#

so its my ddol setup for the game manager thats wrong

#
{
    private void Awake()
    {
        if (FindObjectOfType(typeof(GameManager)) != null)
        {
            Destroy(gameObject);
        }
        DontDestroyOnLoad(gameObject);  
    }
}```

currently is this
languid spire
#

that is insane

short hazel
#

It works

jaunty bay
#

it works?

languid spire
#

what? find yourself and then destroy yourself

jaunty bay
#

i setup GameManager in all the scenes

#

find the ones that isnt this one,

#

(in which i think thats the problem)

#

and deletes it

languid spire
#

that is not what that code does

short hazel
#

"that isn't this one" is missing in your code

jaunty bay
#

okk lemme try smthing

short hazel
#

You'd usually pair that with the singleton pattern, to have a static reference available

stone pilot
#

but thanks for the help :)

languid spire
stone pilot
#

I make a transition from the takeOf to the Idle

#

and then I called it when the player is grounded

atomic holly
#

Is there a solution to do an action one time if the condition is true and after still the condition is true, do something else
For example ```c#
if(value1 == value2)
-> value1 += 1; (do this one time)
-> value2 += 2; (do this still the condition is true)

short hazel
#

Sure, keep track of the number of times the condition was satisfied with another variable, and use that in an if statement

#
if (v1 == v2)
{
  count++;

  if (count == 1)
    // do stuff 1
  else if (count == 2)
    // do stuff 2
}
#

And reset the variable back to 0 when needed

atomic holly
#

I do it with a boolean but it's okay.
I just wanted to know if it was something integrate in the C# or Unity to do something like this

short hazel
#

Nothing that I know of, it's too specific to have it implemented in the base libraries

languid spire
quaint island
#

Hello, i want to ask something about Unity and Visual Studio (Not code).

When i open file the Intellisense work fine (Just like the first picture).

But when i create new file and open the file those file intellisense not working for Unity Class or Namespace Like (Monobehaviour etc).
Example: in second picture

Anybody know how to fix this?

languid spire
#

note this is a part of the project
and this is not

quaint island
umbral rock
#

void Update()
{
if(Input.GetKey(KeyCode.Space)){
rb.velocity = new Vector2(rb.velocity.x, +10);
Debug.Log("Space Is Pressed");
}else{
rb.velocity = new Vector2(rb.velocity.x, 0);
}if(Input.GetKey(KeyCode.LeftControl)){
rb.velocity = new Vector2(rb.velocity.x, -10);
}else{
rb.velocity = new Vector2(rb.velocity.x, 0);
}
}
}
why does this not work?

languid spire
quaint island
languid spire
quaint island
#

I forgot to add:
On my old laptop when i create file immediately from Visual Studio its always immediately connect and has Intellisense for Unity

quaint island
languid spire
quaint island
languid spire
lapis frigate
#

I have a turned-based combat system and that is how I load in an enemy, as of right now I can only load one enemy, what is the best way to control which enemy I load into the scene each time?

burnt vapor
#

One spawns enemies, another one shows it on the hud

lapis frigate
#

so like create an enemy manager?

burnt vapor
#

Yes, pretty much

quaint island
burnt vapor
#

But this is not as relevant. If you want multiple enemies, make more prefabs that represent these enemies. Then you could, for example, set up a dictionary and set them under a key. Then your manager takes this key and it will get the corresponding prefab

#

This is just one way, obviously.

#

But I'd recommend you don't couple your code like you do now, because now it's hard to fix your issue.

#

Or you pass all your data into SetupBattle, but that method should not worry about this

lapis frigate
# burnt vapor Yes, pretty much

and like how do I actualy load the enemies cuz the only way I thought about is to build a method that gets a name and then a very long if list that checks if the enemy need to be loaded by name

burnt vapor
languid spire
burnt vapor
#

Using a list gives the issue of filtering, or knowing their index. A dictionary allows for a known key to be set.

lapis frigate
#

and I should save like all the enemies as prefabs?

#

in the enemies folder?

burnt vapor
#

Well, it kind of depends

#

How complex are they?

lapis frigate
#

now not complex at all but idk if it will stay like that

burnt vapor
#

If they just differ in sprite then you could just keep it simple and specify the sprite name to render in a script

#

But if it has varying behaviour or even more than a single sprite I would probably make separate prefabs and store behaviour in its own script for each enemy

burnt vapor
#

You can just store the prefabs in a dictionary. If your manager's Awake method is called you could fill it in, for example

lapis frigate
#

but shoud I load them in using instantiate?

burnt vapor
#

Feel free to ping me. Just make sure to not overcomplicate it

burnt vapor
lapis frigate
#

all right thank you for your help

#

wish me luck cuz i will need that lol

burnt vapor
#

Well, remember there are multiple ways of tackling this. Right now I gave a solution that's quite big but scales well, so you can also start simpler if you want

lapis frigate
#

1 more question

#

every time the enemy is loaded its loaded by its name, and cuz of that I cant use GameObject.find is there a solution to that?

quaint island
burnt vapor
#

Instead the manager helps here quite a bit actually

#

You can make your manager a singleton: https://unity.huh.how/references/singletons
What happens is that your manager can now be accessed from anywhere. This works well because you only have one manager to manage your enemies.

#

Anyway, this manager spawns your enemies. What you can do then is when you spawn your enemy, you store the instantiated gameobject in a list in your manager.

languid spire
burnt vapor
#

So now, if you want to find your enemy again, check this list. If you want more control you can once again use a dictionary with custom keys. Alternatively, store them under their "type" in a dictionary, and then it could return all enemies of a given type.

#

You can also try using your Find method, but remember that calling it is slow. Prefer caching its result if possible.

lapis frigate
#

allright

#

I really appriciate it

#

thank you a lot

languid spire
quaint island
#

ok

#

I create new file name "Testr.cs" and when i check the .csproj
It was referenced, seems like the csproj not blocked.

Edit: Add more detail

clever idol
short hazel
#

I told you what you needed to do

clever idol
#

i cant find a dupe of anything

short hazel
#

You have two classes with the same name, remove one

maiden chasm
#

pls help the i would like reset my paswort but its dosentworking

burnt vapor
#

Perhaps check through file explorer. Unity might not show the file.

languid spire
clever idol
quaint island
languid spire
#

Are there scripts which are not?

quaint island
#

since it cant get unityengine namespace

short hazel
# clever idol i dont think its just 1 dupelicate

The errors are caused by the duplicates. It sees that the class is there twice, and it thinks all its members (fields, methods) already exist, so it throws errors everywhere. Removing the duplicate file will fix all the errors.

quaint island
burnt vapor
languid spire
clever idol
#

i checked it over and over again, even asked chatgpt and it still doesnt work

burnt vapor
burnt vapor
#

Open your project in file explorer, navigate to the folder and look for the file.

short hazel
#

My man, it's not a code problem. You literally need to use your eyes to spot the duplicate file

burnt vapor
#

Surely you could spot a file that doesn't belong if you check in it.

clever idol
burnt vapor
#

I'm talking about a file, possibly with - Copy suffixed, sitting in the folder

#

How about you check and then come back

languid spire
short hazel
#

I scrolled back up to your original screenshot and it's literally here. You have a PlayerController2D (2).cs aside the "correct" one

#

Just get rid of it!

burnt vapor
#

Yeah I don't understand what's so hard about checking the folder because this would be very obvious

clever idol
#

i have fixed something apperently cuz i ony have 3 errors left

short hazel
#

"apparently"

clever idol
short hazel
#

lmao

burnt vapor
#

Yes, you removed the file

short hazel
#

Yeah those are legitimate errors not linked to the duplicate class

quaint island
burnt vapor
#

Well done, now all that's left is an actual coding issue

clever idol
#

broo im new to this alright? sorry i took me so long

languid spire
clever idol
#

I FIXED IT 🥳

#

with your help

short hazel
#

Just have to follow instructions, it's not hard
You'll run into issues very quick if you don't apply them, unlike human beings, computers will do exactly what you tell it to do

lapis frigate
#

Is there a way to change what is connected to a game object trough code?

#

like this for exapmle ^^

cosmic quail
weak cedar
lapis frigate
#

yes

#

i have a turn based combat game and im trying to figure out a way to load a diffrent enemy each time

weak cedar
#

Well you could make a list and have EnemyPrefab1, EnemyPrefab2, EnemyPrefab3 and so on

#

Then load different EnemyPrefabs

cosmic quail
burnt vapor
#

If the variable is private or inaccessible, then you can't change it from code without reflection.

languid spire
lapis frigate
#

I created an enemy manager and created a script for it, should I also add the battleSystem script as a component?

burnt vapor
#

Also, you don't need Resources.Load. If you know the enemies beforehand you can set up a list or dictionary and assign enemy prefabs there that must spawn.

cosmic quail
lapis frigate
quaint tree
#

Where do you guys suggesting going if I want to pay someone to code part of my game?

cosmic quail
#

and this channel is only for code questions

burnt vapor
#

Lastly try to store spawned enemies in a list and then see if you can set it up in that loader code you showed

lapis frigate
#

ok i will try

weak cedar
#

!code

eternal falconBOT
queen adder
#

UGH
Lerp is STILL having the Max be 1

steep rose
#

thats what lerp does

#

i see no issue with it

queen adder
verbal dome
#

LerpUnclamped?

queen adder
#

Ill show code

queen adder
#
private void motionPhysics()
 {
     body.AddForce(Vector2.right * CharacterSpeed);
     if (movement)
     {
         CharacterSpeed = Mathf.Lerp(CharacterSpeed, top_Speed, velPower * Time.fixedDeltaTime);
     }
     testingUI.text = CharacterSpeed.ToString() + "         " + body.velocity.ToString();
 }```
#

I want the Variable shown to be what Top_Speed is which is 11.0f

verbal dome
#

Perhaps you want to use lerp correctly, or use Mathf.MoveTowards for constant change

wheat coral
#

Hi I have a question
So I get the transform component reference of a child object then I tried to change its x and y position by inputs but whenever I change any position by pressing key it also changes z axis position while I put it as objectTransform.position.z

Please🥺 help me

rocky canyon
#

!code show code and ur hiearchy / set up of these objects

eternal falconBOT
drowsy oriole
#

I want to make it so, when (Private bool ColliderUse) is TRUE then object(s) are enabled

steep rose
drowsy oriole
#

I dont know how to do that

steep rose
eternal falconBOT
#

:teacher: Unity Learn ↗

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

drowsy oriole
#

Dude... I want to make GameObject WaterCollider turn off when ColliderUse is true

steep rose
#

we will not just make code for you

drowsy oriole
#

I am adding a Swimming feature and I don't remember how to use SetActive on a GameObject

weak cedar
weak cedar
drowsy oriole
steep rose
#

use docs for something you dont know

weak cedar
drowsy oriole
#

It worked

steep rose
midnight meteor
#

Hello , can i use the start method in a scriptableobject ?

short hazel
#

I don't think so, but you can try it. Place a log in it, and see if it gets called at the right times

#

If it gets called at all

midnight meteor
#

oh okay

#

thank you

slender nymph
#

this is a code channel

undone harbor
#

oh my bad

silver monolith
#

I am completely new to unity and i was trying to add a physics material to my rigidbody2d but it doesn't work

silver monolith
#

and it wasn't in the menu

rich adder
silver monolith
#

is it in legacy or something

rich adder
silver monolith
#

ok

lapis frigate
#

How do I access a prefab in a folder in my project trough code?

lapis frigate
#

does that work with 2d?

weak cedar
#

of course why wouldn't it

#

they are all .asset files anyway

lapis frigate
#

so should I use Resources.Load?

terse spindle
#

hello
I have an empty object for ground checking but how do I make it that the empty goes with the player and not anchoring in some place

#

it dont move with the player

rich adder
terse spindle
#

it is a child of the player

rich adder
#

then it will move with the player

#

unless you have code setting it to do otherwise

terse spindle
rich adder
# terse spindle

you have it parented to the mesh not the bones that actually move

terse spindle
#

doesnt the mesh move too

rich adder
#

not really the mesh is just a "skin" placed above the bones just visuals

terse spindle
#

thank you

weak cedar
terse spindle
rich adder
#

how you both got the same pfp

#

lol

queen adder
#

How can i access the Application.version outside of main thread?

weak cedar
queen adder
weak cedar
#

make a string

#

private string appVersion

queen adder
#

So there is no way to get the version of the game outside of main thread?

weak cedar
#

then in the start/awake, appVersion = Application.Version;

rich adder
weak cedar
#

you can access appVersion later on

weak cedar
#

string appVersion = "";

#

then in Awake/Start, appVersion = Application.version

queen adder
rich adder
weak cedar
queen adder
#

Bet it is because their backend takes that information from their "unity instance"... this is bullshit

rich adder
#

you can make it a property tho

public string AppVersion => Application.version

lapis frigate
#

if thats even possible

rich adder
weak cedar
#

Create a folder called resources and place that prefab in the folder

lapis frigate
#

you mean like drag all the diffrent enemies into the inspector then load the one I need?

rich adder
#

yes

lapis frigate
#

isn't it a bit impractical when i will have dozens of enemies?

rich adder
#

how is what you're doing more practical ?

lapis frigate
#

umm idk I guess if i will have them stored in an enemies folder then I can load them from that folder will be easier?

rich adder
#

yea but if you change name or move it as some point it breaks

#

It also depends how you distinguish what you're trying to spawn

lapis frigate
rich adder
#

you didn't read the docs did you

#

I sent you the docs

lapis frigate
#

I did but I didn't understand much

rich adder
#

it literally shows example how to grab it

weak cedar
rich adder
#

you wrote it wrong

#

there are multiple things wrong with it

weak cedar
#

This screenshot should be telling you everything you need

rich adder
foggy void
#

🤔 Is there any way in unity to globally slow down a game?

#

(Not Time.timeScale)

weak cedar
rich adder
foggy void
#

Damn okay I might just purposefully lower fps then

rich adder
#

that sounds awful game experience

weak cedar
#

Why don't u type this in google

lapis frigate
#

tbh at this point I think coding is my kryptonite

foggy void
#

Google didn't really give any results besides time.timescale

weak cedar
#

ask chatgpt?

foggy void
#

Nor did chatgpt, actually it suggested me to manually lag.. XD

weak cedar
rich adder
lapis frigate
#

I mean I put it in Recources folder then assinged it to the enmy unit

foggy void
#

I guess so

lapis frigate
#

and its still gives the same error

rich adder
#

no one can do anything without seeing what you did

weak cedar
#

The point of Resources.Load is to load it from the Resources folder

lapis frigate
rich adder
#

so you didnt read again the docs on how to correctly write it ?

lapis frigate
#

but I cant change it if I dont assign it into the enemy unit

rich adder
#

even though the page tells you exactly how to write it

lapis frigate
weak cedar
#

if Dwayne.prefab is in the Resources folder

#

then Resources.Load<GameObject>("Dwayne")

#

You don't need the ".prefab"

lapis frigate
#

just the "Dwayne"?

rich adder
#

maybe they would've read it but they like spoon feeding

lapis frigate
#

without the Assets/Resources?

weak cedar
#

Yes.

#

You would have solved this problem like 20 mins ago just by reading the docs

rich adder
#

if you want to get anywhere in code/development you have to make it a habit to read, especially the documentation/manual

lapis frigate
#

I get that but tbh when I read code examples I feel like my english level is degrading

#

and tbh every time I look for an example it uses another method that I dont know in the example

rich adder
#

its in plain english, the same words we're using

#

there is no magic

rich adder
#

🤷‍♂️

lapis frigate
#

I guess you are right

livid grail
#

Hey Guys! Im struggling with List.Add..
I know how to do it with gameobjects/ strings etc but my list is based of a custom function " dont know if that is the correct term, sorry"
and I dont know how to add it correctly
The setup:

public List<Digit> digitData = new();

    [System.Serializable]
    public class Digit
    {
        public int representingNumber;
        public float rotationAngle;
    }

Where I want to add and set the parameters

   private void AssignDigits()
    {       
        for(int i = 0; i < NumberAmount; i ++)
        {
            digitData[i].representingNumber = i+1;
            digitData[i].rotationAngle = i * rotationAmount;
        }
    }

Right now I set the list size manually in the inspector but that isnt ideal

rich adder
#

unity docs tbh is one of the actual ones that are pretty clear in comparison

lapis frigate
#

ye I get that You helped to much to come at me

rich adder
eternal falconBOT
rich adder
#

aka a type

#

.add should work just fine, make sure you are actually creating an instance new() of the item you want to add to list

weak cedar
#

I would recommend the foreach loop

#

Also, you are changing the variables of null elements

#

digitalData[i] does not exist yet because you didn't .add one yet

rich adder
#

they have elements

weak cedar
#

Or you added it somewhere else in your code and I can't see it

rich adder
#

they said it was added in the inspector

#

they are probably struggling creating a new instance of Digit to pass to Add

weak cedar
#

They said they set the size

rich adder
#

that creates elements (populates the list with null items)

#

in the inspector

quick pollen
#

@still wren u managed to solve the out of bounds issue?

rich adder
#

without knowing what OP true issue was with Add without detail, pretty sure the issue is they probably did not know how to do a new instance and add it to the list via code

weak cedar
#

I would create a constructor new Digit(int repNumber, float rotAngle) then digitData.Add(new Digit(i + 1, i * rotationAmount))

weak cedar
quick pollen
#

I think

#

someone correct me if im wrong

rich adder
livid grail
#

Thanks for correcting me about the code snippet, and teaching me about the correct term 🙂
and yes that is correct Im struggling to create a new element in the code, I thought that it would have looked something like this but I was wrong

 private void AssignDigits()
    {       
        for(int i = 0; i < NumberAmount; i ++)
        {
            Digit temp;
            temp.representingNumber = i + 1;
            temp.rotationAngle = i * rotationAmount;
            digitData.Add(temp);
        }
    }
quick pollen
#

this is the image he sent

#

thats how it works, right?

rich adder
#

that creates a new Instance of that class

#

you can also assign a constructor to it that can take in the data you want as parameters as shown in example above

weak cedar
livid grail
#

works like a charm

rich adder
#

might want to do a quick crashcourse on c# 😛 check pins in this channel as well

livid grail
#

heh yeah I really should, I know quite a lot but then at the same time I know very little about some of the most basics things xD.
self taught 😬

rich adder
#

haha yea I feel that as self taught its harder to know which topic to go for, doesn't hurt to refresh on a few things in the beginning just have to engrain them in the mind by repetition

neon ivy
#

is there a way to access a variable via a string of the name or id?
so for instance:

public class TestClass
{
  public int variable1;
  public float variable2;
}
public class OtherClass
{
  var variable;
  void GetVar(string id)
  {
    variable = // get variable based on ID
  }
}
#

the best I can think of is to make a function that returns T with a switch case in it but that's not very dynamic

deft grail
cosmic dagger
neon ivy
#

so I wouldn't be able to set it?

rich adder
neon ivy
#

I can see how u can make a dict for reference types cuz u can pass through the reference, but u can't do that with data types right?

rich adder
neon ivy
#

value type* mb

#

also u'd have to make a dict for each type, unless u can make a <string,T> dict? that sounds silly

teal viper
languid spire
#

Dictionary<string, object>

neon ivy
#

ooh object

rich adder
#

that or , just make a containing class or struct

rich adder
# neon ivy I can see how u can make a dict for reference types cuz u can pass through the r...
public Dictionary<string, float> valueTypes = new();
public Dictionary<string, Transform> referenceTypes = new();
private void Awake()
{
  Vector3 position = referenceTypes["someId"].position; //gets copy of pos (v3 is a value type)
    referenceTypes["someId"].name = "Something";//changing the original
    position = new Vector3 (32f,32f,3f); // does not change original pos

    float value = valueTypes["someId"];
    value = 23; //does not change the original, its only a copy

}```
neon ivy
#

the idea is that I made a chat system so I can create commands like in minecraft so I was wondering how I could set up a dynamic way to set variables from the game itself.
so like /SetVar [script reference] [variableID] [value] which would be nice for debugging in a build

rich adder
#

literally a dictionary

#

you can even store functions

neon ivy
#

is a delegate an object? poi_shock

rich adder
#

you're using OOP everything is an object 😛

neon ivy
#

fair xD. so I'd have a <string,object> dict, could I put it in an interface ICommandable so I can gather any ICommandable script in scene? think I remember being able to make value types in interfaces as long as they do the {get;set;} thing

rich adder
#

as long its a property or method it can be there

neon ivy
#

so a dict property? UnityChanHuh the difference between a variable and a property kinda go over my head, they seem like the same thing most of the time to me

rich adder
#

so you can cram extra logic inside when you get or set a value

neon ivy
#

if that's the only difference, why can't an interface have fields but it can have properties?

rich adder
# neon ivy if that's the only difference, why can't an interface have fields but it can hav...

An interface can't contain constants, fields, operators, instance constructors, finalizers, or types. Interface members are automatically public, and they can't include any access modifiers. Members also can't be static.
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/interfaces

obsidian granite
#

and interfaces can have methods

#

that's my understanding, at least

ashen niche
#
using TMPro;

public class green : MonoBehaviour
{
    public TextMeshPro tmp;
    public int amountToAdd = 1; 

    private int moneyAmount = 0;  

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.name.Contains("Circle"))
        {
            if (gameObject.name.Contains("green"))
            {
                Destroy(collision.gameObject);

                moneyAmount += amountToAdd;

                tmp.text = "$: " + moneyAmount;
            }
        }
    }
}
``` the code works but majority of the time when the circle collides with the green it can remove from the money amount ex: money at 3, circle colides with green, money goes down to 1. does any1 know why this happens?
teal viper
rich adder
rich adder
# ashen niche six

so you still have them change the same text with their own new values?

neon ivy
rich adder
#

you can't assign any values (oh thought you were talking about interface initializer)

teal viper
thorny basalt
neon ivy
#

oooooh

#

that actually makes a lot of sense... UnityChanCoder

teal viper
#

Properties are basically a syntactic sugar. In Java you have to use actual methods for that.

#

There's a lot of features like that in C# that the compiler does for you.

neon ivy
#

I was actually coding a web API for a database a while back in java and I was wondering why I had to make a get and set method for each variable think I guess C# is just very nice xD

rich adder
#

microsoft java is much nicer UnityChanLOL

teal viper
#

Yeah, you can think of C# as java on steroids.

rich adder
#

chadJava

thorny basalt
#

We have 1 line encapsulation 😎

neon ivy
rich adder
jaunty bay
#

henlo, a quick confirmation question

transform.position = spawnHandler.spawnTransform.position;

this will change the current object's position to SpawnHandler's (script) spawnTransform (a Transform) position, correct?

#
GameObject gameManager = GameObject.Find("GameManager");
spawnHandler = gameManager.GetComponent<SpawnHandler>();```
polar acorn
#

Yes, whenever this line runs, it will set the position of this object to the position of the other

jaunty bay
#

hmm, ok sec

rich adder
cosmic dagger
rich adder
teal viper
#

Where's the function identifier/name?

#

It's not that different than C# until you get into templates. I hate templates.

#

And macros

#

Just need to know what the const keyword does in each situation and references/pointers obviously.

cosmic dagger
teal viper
cosmic dagger
#

My biggest thing is learning when to use a reference or a pointer since a pointer is a reference but with more power, haha . . .

teal viper
#

I'd say the same as public fields in C#. Avoid at all costs, unless absolutely necessary.

#

Though, maybe that's an exaggeration.

#

Since nullptr can be useful.

#

I guess passing a value type by ref vs using a reference type instead, is a better analogy.

cosmic dagger
teal viper
cosmic dagger
#

Once I get the control flow down, it'll be more manageable. I will say, refactoring is more complicated. I get lost going from file to file and trying to avoid classes included multiple times from other header files. I have a StateMachine that needs the header from State and vice-versa, so I have to figure that one out . . .

late burrow
#

reading json is much less enjoyable than writing it half of functions not work

static wasp
#

my jumps right now feel very weird and smooth, which is not what i want

cosmic dagger
deft grail
#

or do you mean the hold button to go higher

static wasp
deft grail
#

you can probably find the exact numbers online

#

if they use a rigidbody also

deft grail
static wasp
#

when i add more mass, i don't jump as high, i want to jump the same height, but i want a higher gravity

deft grail
#

also change gravity and stuff

static wasp
deft grail
# static wasp how

you can do it in project settings i think, not sure if thats the ONLY place or not

static wasp
#

is it in the rigidbody section?

deft grail
#

probably in the docs

slender nymph
#

2d rigidbody has a gravity scale property you can assign to

static wasp
#

thanks

slender nymph
#

what i personally like to do is keep gravity scale around 1 when grounded or performing a jump, then at the apex of the jump (or when pressing down) increase gravity scale so the object falls quicker. you can also compensate for your reduced jump height by simply increasing the amount of force applied

static wasp
#

but, how do i access the gravity scale from a script?

deft grail
# static wasp thanks

theres videos for that on youtube you can find if you want, ive seen it before.
its a pretty common technique

deft grail
static wasp
teal viper
#

Check the documentation for the available API.

rich adder
# cosmic dagger honestly, i just want to make a text-based dungeon crawler. move to a room, choo...

a good idea for learning project to do for sure, I did a much simpler text based rpg with one of my first projects in C# console, taught me a lot, esp working with loops something I wasn't comfortable with in the beginning.
And yeah for current project I'm working dealing with hardware and microcontrollers, is to be used in Unity. For this I need such low language, it really makes you appreciate such high level languages like C# at least lol Its good feel though to have such little programs be so efficient and fast.
Eventually the plan is to move onto playing around with more bare metal controllers and C++ seems the next step

main karma
#

guys how to check for fps in a build

hardy maple
teal viper
main karma
hardy maple
signal cosmos
#

I have a problem; I tried using Firebase's real-time database, but it's not supported on Android. Do you have any alternatives you can suggest, or how do you handle databases in your games to ensure it's convenient?

potent olive
#

would anyone happen to know what the hell is going on here? anything labelled "Input" is a textmeshpro text input. theyre all strings, shouldnt they all work?

This happens for both RefreshContainer() and RefreshValues()

RefreshContainer() is called whenever a text input is changed

teal viper
signal cosmos
potent olive
slender nymph
potent olive
#

...interesting.

teal viper
# signal cosmos auth2 + save load system

Not sure what auth2 is exactly(some kind of authentication system?) and why you need a database for it, but database for saving and loading is probably not a great idea. Are you developing an MMO with thousands of players?

#

Is the save data supposed to be saved on the cloud or locally is fine?

potent olive
#

yeah...that didn't work.

slender nymph
#

have you considered using the debugger to inspect what the string actually is? or even printing it?

potent olive
#

i didn't think I'd need to, but here it is anyways

#

also id like to note that the lines for the .name work perfectly fine, but only when the other lines are commented

slender nymph
#

the name property can have whitespace in it. whitespace is, notably, not an integer though

potent olive
#

it does not have whitespace

slender nymph
#

how have you confirmed that

potent olive
#

the input field does not allow it

#

character validation: integer

slender nymph
#

well then i guess your string is in the correct format for int.Parse! congrats on not having an issue, i guess

potent olive
#

uh, thanks? my issue isn't fixed though-

slender nymph
#

so then what do you think that indicates?

#

because you've printed the strings and see that the only visible characters are integers, and yet it's still not in the correct format for int.Parse

potent olive
#

i'm not sure we're on the same page, the issue isnt just for int.Parse

slender nymph
#

are you still going to try insisting that there is no whitespace in your string?

#

also, yes the issue is just for int.Parse. it's literally what is throwing the exception

#

the code after the int.Parse line cannot run because an exception was encountered

potent olive
#

i'm trying to be polite here. there are two fuctions, both of which fail. One of them does not use int.Parse

slender nymph
#

you have not shown any stack trace that has anything to do with any other method

potent olive
slender nymph
#

holy shit dude, did you even look at the most recent part of the stack trace?

#

your issue is literally still int.Parse because you are modifying the text object which invokes the event which invokes the method that invokes int.Parse

potent olive
#

also note that when this screenshot was taken, RefreshContainer() was NOT being called and the Parse lines were commented out anyways.

slender nymph
#

can you read?

potent olive
#

however it's still not explained, since again, the parse lines are commented out.

slender nymph
#

i will ask once more, can you read?

potent olive
#

oh wait

#

whoops

#

nevermind, that's entirely my fault 😅

slender nymph
#

yeah so anyway, the issue is whitespace in the string

#

that Trim call you have only trims that one whitespace character (which is sadly not trimmed with the default Trim() call)

mighty marsh
#

its my first time using raycast and I'm trying to use a layermask to trigger a function when im looking at a specific function, but it seems to trigger anyways no matter what object i'm looking at or what layer its on

slender nymph
#

show code

mighty marsh
#
    

    // Update is called once per frame
    void Update()
    {
       Ray ray = new Ray(transform.position, transform.forward);
       
        if(Physics.Raycast(ray, raycastLayer))
        {
            turnOnLights();
        }
    }```
#

specific object*

slender nymph
#

you've actually just provided a maxDistance because the first optional parameter for Physics.Raycast that accepts a Ray as the first parameter is the float distance. LayerMask has an implicit cast to int which also has an implicit cast to float
https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
You need to either provide a maxDistance before the raycastLayer parameter, or use Named Arguments

mighty marsh
#

if(Physics.Raycast(ray, maxDistance: 100, raycastLayer)) like this?

slender nymph
#

well if you do that you don't need the named argument

#

but also if you do use the named argument there, you'll need to do so for the layerMask argument as well

mighty marsh
#

it still wasnt working but it was actually an issue with the mesh collider

#

thanks for the help

tawdry trench
#

does anyone know how to have a game object reference another object by name only under its group? So for example, it searches for attackpoint1 under player but not outside of it.

slender nymph
#

Ideally you would get a direct reference to the object instead of trying to find by name. but have you looked at the docs for GameObject.Find or even Transform.Find?

tawdry trench
#

I was using gameObject.Find but when i use that, it also searches stuff outside of the group.

slender nymph
#

i'm guessing that's a "no" on the question about looking at the docs for that method then

tawdry trench
#

yeah no i haven't

#

also the hyperlink leads to a page that doesn't exist

main karma
slender nymph
#

and if you insist on using GameObject.Find then look at the docs to learn how to do what you are asking

tawdry trench
#

yeah i think i got it now ty

royal grotto
#

i got this problem, can anyone help me, havent destroyed anything so i donno what will help 😄

#

i havent made any code ye, just makin map

crystal hornet
#

pretty please ofc

#

with a cherry on top

languid spire
royal grotto
#

aight ill try it

sour fulcrum
#

if i have a class with no constructor like

public class MyClass<T>

public List<T> MyStuff = new List<T>

and i have an instance of it in a class (in this case static but curious in general) like

public static class MyStaticClass

public MyClass<T> MyClassInstance

do I need to initialize it w/ a constructor like public MyClass<T> MyClassInstance = new MyClassInstance<T>() for the class and list to initialize or can i skip that if it doesn't explicitly have a constructor

royal grotto
willow scroll
languid spire
main karma
#

guys how would the player detect a projectile when standing still when using a character controller for the player

crystal hornet
astral meadow
#

can you code that a componement gets added to a object?

#

for example that a script gets added to an object

weak cedar
#

gameObject.AddComponent<ComponentType>();

royal grotto
languid spire
royal grotto
#

2022.3.42f1

languid spire
#

It is obviously a bug in the Terrain Tools package, you could look to see if there is a newer version otherwise you're stuck with it

royal grotto
#

dang xD

#

newer version of terrain tool package?

languid spire
#

yes

royal grotto
#

there isnt

languid spire
# royal grotto there isnt

tbh it's not a critical error. Looking at the stack trace it's just trying to save some settings so it should not affect your project at all

royal grotto
#

aigth

#

in past it stopped me from trying this game

woven crater
#

does setting position to an empty gameobject each frame is the same as set parent transform?
i want to pool the sprite object and make it follow the enemybase, which is in network pool, so when i create enemybase i want to set spriteobject to it and make it follow the enemy base without setting parent because i think it might affect performance

sour fulcrum
#

if i have

MyDerivedClass : base
string coolstringname

can i swap in a base and re-serialize the value like

MyBaseClass
[FormerlySerializedAs("coolstringname")]
string baseString;

MyDerivedClass : MyBaseClass

#

(yes)

languid spire
#

probably not

#

but try it and see

queen adder
languid spire
#

not sure it will work though when you swap out the base class

sharp abyss
#

Do you know how can I limit my linerenderers line and prevent it from going through walls and if I can add a gameobject to the end of the rope. I'm using it as a grappling hook

languid spire
#

to limit the line renderer you would need to raycast each point in the points array as you are building it. To add a gameobject, simply position it at the last point in the points array

pulsar flame
#

Hi. I have a problem. In Unity, any changes that i make don't apply to game and i couldn't find a solution. Could you help me please?

languid spire
pulsar flame
# teal viper What exactly doesn't work?

Any codes that i write, for example in these pictures. I write a Debug.Log("Interval is working"); it works okay but then I removed from codes but it still works. Console show me this debug

verbal dome
#

So you removed debug.log and it still logs?

teal viper
pulsar flame
verbal dome
#

Does unity recompile the scripts?

#

After you save

pulsar flame
#

no it doesn't

verbal dome
#

Then maybe you have turned off auto refresh/auto recompile, whatever it is called

teal viper
#

Or there are compile errors that prevent the compilation.

verbal dome
#

Yeah cant see from the screenshot if you have errors

pulsar flame
#

There is no any compile error

teal viper
verbal dome
#

What IDE? Is that Rider?

pulsar flame
teal viper
pulsar flame
teal viper
#

unhiding the warning in your console might be useful as well

pulsar flame
verbal dome
#

What if you press Ctrl + R in the editor

#

And what unity version is this?

pulsar flame
pulsar flame
verbal dome
#

Okay so auto refresh isnt working

pulsar flame
#

yes but why of :///

verbal dome
pulsar flame
#

thank you bro, you saved my life

verbal dome
#

You said it was enabled earlier 😄 But yeah no problem

pulsar flame
#

😄 sorry it was my bad

late burrow
#

why cant i just get json by providing exact path like i did when writing it

#

thing["a"]["b"]["c"] = stuff

#

instead i have to mess with selecttokens which is so unintuitive

languid spire
#

Now you have a reason to write your own Json library

late burrow
#

im already using this custom one because unity one is even worse

#

where i need to specifically write down classes for it

languid spire
#

Nothing beats rolling your own if it's specific functionality you want

late burrow
#

my own one looked pretty much string.split("key")

#

was nice to use but definelly not performant

languid spire
#

actually Nettonsoft is open source so just grab a copy and mod it

late burrow
#

but what to mod

#

dont tell me you cant just grab by specifying path you could do when writing to it

languid spire
#

I don't know, I don't use it, I have my own Json library (lol)

#

And I certainly can do what you suggested