#💻┃code-beginner

1 messages · Page 820 of 1

sour fulcrum
#

Two spikes shouldn’t randomly be different for no reason

echo copper
#

guys, who knows how to stop the stack's flow for some time. like, the analog on time.sleep() in python but for unity? Thread.Sleep doesn't work for me idk why

sour fulcrum
#

Design your level in a way that doesn’t make this happen

echo copper
# sour fulcrum Why

well, there are some actions i need to do but one should go after previous one

naive pawn
echo copper
#

ohdamn

naive pawn
#

(timers here referring to having a variable that counts time, not the class called Timer)

toxic ledge
#

Shud i try to fixe the code editor ?

#

And if yes can someone maybe help me?

naive pawn
#

are you referring to ide configuration

toxic ledge
#

The one that i some how got it to work very bad

naive pawn
#

do you have proper syntax highlighting, and do you have autocomplete

grand snow
#

syntax highlighting = pretty colours on your code

toxic ledge
#

Let me look

#

I jave blue green blue pink

#

And some other colore idk how to name

#

And ys is outo fills but idk if is the good comand

grand snow
#

If type names, fields and functions appear as you type code then its working

#

also if errors are underlined

naive pawn
toxic ledge
#

and i see this in problems

twin pivot
#
public class Singleton:MonoBehavior
  {
    public static Singleton singleton;
  }
```is this not how you make a singleton?
distant saddle
frail hawk
naive pawn
strong wren
naive pawn
#

is intellicode not the name of the feature within copilot?

#

i thought copilot encompassed a lot more

#

well, i guess now it's "inline suggest" according to the setting names, but that's much vaguer...

sour fulcrum
#

They are killing intellicode

naive pawn
#

the product or the feature

sour fulcrum
#

Former, it’s copilot now

twin pivot
sour fulcrum
#

with limited rates

toxic ledge
naive pawn
sour fulcrum
sour fulcrum
naive pawn
strong wren
toxic ledge
#

shud i reintall video code editor?

naive pawn
#

no, and that's not what it's called

#

do you have intellisense

toxic ledge
#

sorry.

naive pawn
#

are you on windows or mac

sour fulcrum
toxic ledge
#

windows

naive pawn
#

hm i don't remember what the bind to trigger intellisense is on windows.. probably ctrl+space or ctrl+period

naive pawn
sour fulcrum
#

Image prompting i think

toxic ledge
#

if yes is ctrl and space

naive pawn
#

well they aren't commands

toxic ledge
#

scrip or code?

naive pawn
#

if they're showing proper identifiers or keywords, rather than just words in the file, then it's configured properly

#

perhaps show that window

toxic ledge
#

what im talking abt is this window or pop up or how ev you wana call it x3

naive pawn
#

yeah, that's intellisense

#

and that's properly configured then

toxic ledge
#

so i just need to olwos press ctrl space?

#

oke ty tho im not doing now cus ehhh...

#

i dont feel like codeind rn sorry

naive pawn
toxic ledge
#

frist pic is automatic and second is when i press it

#

btw sorry for so meny pics i just cant type well in english

echo copper
#

how to initiate a function inside a command? Can i do smth like Tween.onComplete( void smth {blablabla});

naive pawn
#

it's working normally then

naive pawn
toxic ledge
#

not ryly it give diverent comands i mean

naive pawn
toxic ledge
#

yes?

naive pawn
#

yeah

#

you shouldn't rely on the AI suggestions though

toxic ledge
solar hill
#

You wont learn any better with using AI

#

People have been learning to code the old fashioned way for over 40 years now, people pretend like its suddenly impossible without AI

elfin pike
#

I cant decide. I have class which stores dictionary( SO and id). Where should i make id? in dictionary class or ScriptableObject?

toxic ledge
sour fulcrum
#

read lol

elfin pike
solar hill
toxic ledge
solar hill
#

Tutorials, courses, guides, books etc.

#

Not AI

elfin pike
toxic ledge
elfin pike
#

I think paid courses are scam. there are courses for free

toxic ledge
elfin pike
twin pivot
verbal dome
#

Like where to declare the type or?

solar hill
toxic ledge
elfin pike
# toxic ledge code what i have 0 expiriense

I had maybe small experience, but you could say i had 0. Then started doing these steps.

  1. What i want to make?
  2. How much time will it take? Triple time
  3. Start coding
  4. fix or look up examples if something doesnt work
solar hill
verbal dome
radiant voidBOT
twin pivot
#

Maybe cubing time would be better XD

elfin pike
naive pawn
naive pawn
#

are you asking whether to store the id in the SO or not?

verbal dome
#

Or where to generate the ID?

#

I'm still confused

toxic ledge
elfin pike
toxic ledge
naive pawn
#

you should probably store the id in the SO, to have a reverse mapping.

thus, you should probably make the id in the SO

elfin pike
verbal dome
#

Yeah sounds like the SO should own the ID

naive pawn
elfin pike
naive pawn
#

why OnValidate

#

seems a bit unnecessary to refresh the ID that frequently?

queen vale
#

Another day, another bug. Goodmorning people

naive pawn
#

i feel like Reset or Awake would be adequate, depending on the lifetime of the dictionary in question

toxic ledge
elfin pike
naive pawn
#

if it doesn't work out, there are other tutorials for you to try

#

but you won't learn at all if you never start

naive pawn
verbal dome
# elfin pike Doesnt it get called, when data is added in inspector?

It gets called in a bunch of places
https://docs.unity3d.com/6000.3/Documentation/ScriptReference/MonoBehaviour.OnValidate.html

OnValidate is called at various stages during the Editor's normal operation, such as loading scenes, building a Player, and entering Play mode.

OnValidate can be called often when the user interacts with an Inspector in the Editor. It can also be called from threads other than Unity's main thread, such as the loading thread. For these reasons, only use OnValidate to validate the data that changed. Don't use it to do other tasks such as creating objects or calling other non-thread-safe Unity API.

queen vale
#

You also don't learn by copy-pasting tutorial code. Gotta play with it, see when/why it works, read about it. Try to use it in different ways.

verbal dome
elfin pike
verbal dome
#

(If i understand correctly you have some dictionary wrapper class?)

#

Or where is the dictionary stored

naive pawn
elfin pike
#
public class SO_Dictionary : ScriptableObject
{
    [SerializedDictionary("ID", "ScriptableObject")]
    public SerializedDictionary<int, ScriptableObject> db;

    void OnValidate()
    {
       

    }
}```
naive pawn
#

you can't put the SO in without a key

elfin pike
#

I made it as SO, because it will be reused for other SO. Maybe i should add Interface for id SO

naive pawn
#

what's the overall goal here?

elfin pike
#

yesterday i asked and got answer, that dictionary would be best option for it

naive pawn
#

and you want to add serializedobjects to the dictionary in the editor?

#

i'm not sure a serializeddictionary is the best flow for that

#

you could just have an array/list to add to, and then build the dictionary in memory

#

having the id serialized in 2 places seems like a potential spot for mistakes, just accidentally changing the ID or something like that

elfin pike
naive pawn
#

and you wouldn't want to have to constantly refresh the serializeddictionary

naive pawn
elfin pike
elfin pike
toxic ledge
#

So all i do when codeing is trying and hopeing it works and then if it dosent i seek help?

naive pawn
naive pawn
elfin pike
naive pawn
echo copper
toxic ledge
naive pawn
naive pawn
echo copper
green arch
naive pawn
# echo copper what's wrong here?

presumably you did not assign an AudioClip to the AudioSource, and you aren't providing an AudioSource there, so it doesn't know what you want it to play

toxic ledge
echo copper
green arch
#

oh youre using getcomponent

echo copper
green arch
#

getcomponent is terrible imo

#

assign it in the editor

#

do public audiosource...

echo copper
#

ok

green arch
#

and assign it in the editor

#

and see

#

probably getcomponent isnt finding it

queen vale
#

Is butt the component this adiosource attached to and how is the function being called?
Debug.log is a good idea, see if the function is even being ran.

green arch
naive pawn
echo copper
echo copper
#

thanks'

green arch
#

np

echo copper
#

btw, there is a small delay before playing the sound. how to fix it?

toxic ledge
queen vale
#

The delay is likely due to your SoundClip having blank space (* the clip/audio file may have an amount of time prior to the desired sound/noise.)

naive pawn
green arch
# toxic ledge There is none

I'd say using something like chatGPT would be a good resource for you. But it sucks not knowing english, english is my 4th language and man am i glad to know it, resources in other languages are hard

queen vale
green arch
#

if you're romanian, learning french would be easier imo

naive pawn
#

ah i missed the singular message that mentioned that. mb

queen vale
#

I think I misunderstand something... they mentioned a delay, the first thing my mind goes to is the audioclip (soundclip is the wrong term) having no ("blank") sound for x time

elfin pike
naive pawn
elfin pike
#

Part about doing both? in the end i should create id on SO and then add to dictionary

naive pawn
#

and you can build the forward mapping dynamically, so it isn't serialized (where you can accidentally mess it up)

echo copper
#

guys, please. how to remove the delay in playing sounds in unity? there is no delays in my sound

naive pawn
#

that's why i said to consider a list/array instead

queen vale
solar hill
#

How should we know without seeing it

queen vale
#

Hard to say without seeing

toxic ledge
solar hill
#

!code

twin pivot
# toxic ledge No

Just start to the best of ur ability and google whatever issues ur facing and if u cant find/understand something ask here for help

radiant voidBOT
echo copper
solar hill
solar hill
echo copper
echo copper
green arch
elfin pike
toxic ledge
twin pivot
queen vale
#

Fear only keeps you from learning

elfin pike
toxic ledge
naive pawn
solar hill
# echo copper 62 Kb

Gonna go on a whim and say it might be related to your scene manager loading, if its doing anything async it might cause lag that delays the audio

twin pivot
#

Trust me half the times i ask for help here i realize its something really simple and kick myself

queen vale
# toxic ledge Can you explain abit more pls?

"Scope" refers to... the grand idea of your project, how much is involved to create the final project... and MMORPG, has a TON of things going into it... a match 3 puzzle game is much more simple compared to that.

solar hill
elfin pike
green arch
# twin pivot Chatgpt will spit out wrong information confidently

if you don't know how to code and there arent a lot of resources in your language, asking it to explain simple tutorial scripts is probably something it can handle. I understand LLMs can spit out wrong information, but if he doesn't know english very well, it could be a very good resource imo

solar hill
#

Great thing about coding is that theres almost always resources in every language

green arch
#

are there many tutorials available with subtitles for romanian ?

#

because youtube's auto trancription thing is getting quite good as well

toxic ledge
naive pawn
elfin pike
#

When world stopped using machine learning and chat bots, and started to use word AI for everything that isnt AI

solar hill
#

What exactly is there to be shy about

#

We dont know you

#

You dont know us

elfin pike
queen vale
toxic ledge
naive pawn
queen vale
#

Just gotta bang your head on the wall long enough to find the answer

solar hill
toxic ledge
solar hill
#

And

#

What of it

naive pawn
#

kuzmo comes back every day

elfin pike
naive pawn
#

many of the people here, active right now, ask questions frequently. it's how learning works

queen vale
elfin pike
naive pawn
#

-# 5 years ago was 2017, right...?

twin pivot
#

Like i have already accepted that i know nothing and any question i ask will probably be stupid so if im gonna be stupid might as well ask people for help sooner than later

solar hill
queen vale
#

.... it's 2026, 2026-5 = 2021..?

toxic ledge
twin pivot
green arch
#

damn, no gifs in this server ? atwhatcost

solar hill
naive pawn
#

-# it was a joke, yall

green arch
toxic ledge
queen vale
naive pawn
#

yeah notlikethis

#

-# was saying "5 years ago" feels like 2017

queen vale
#

Fair though

twin pivot
#

Idk man it still feels like 2020 to me

queen vale
#

covid era made it feel like a leap in time imo

#

.... what a time to get quiet ...

elfin pike
toxic ledge
#

Well uhh il try tomarow cus today i feel burned out sorry :<

elfin pike
naive pawn
#

ooo i forgot about building the actual dict. docs say to use OnEnable instead of Awake so it'd build when you enter playmode

elfin pike
naive pawn
#

you could have separate SOs for different types maybe, depending on what you need it to be able to hold overall

#

(though why can't you just reference SOs directly again?)

elfin pike
#

idk, im dumb. I could just add this logic in my static class

naive pawn
#

no like is this an addressibles thing or what

#

why do you need the indirection?

elfin pike
naive pawn
#

why do you need IDs

#

why can you not just reference the SOs

elfin pike
naive pawn
#

cool, that answers my question

green arch
#

if you want to implement like a game save, you can serialize and deserialize them

elfin pike
green arch
#

have a field like playtime

#

for instance

#

setPlaytime(int something) on the moniobehaviour

#

writes to the data

elfin pike
#

give documentation

green arch
#

i did this a while back

#

let me see if i can get the scripts for you

#

okay here's an example

#

i have something like

public class BlockData : ScriptableObject
{
    public string blockName = "Block";
    public bool isImmovable = false;
    public GameObject blockPrefab;
    public Vector3 BlockPosition;


    public enum BlockColor
    {
        White,
        Red,
        Yellow,
        Blue,
        Purple,
        Orange,
        Green,
        Black
    }

    public BlockColor blockColor = BlockColor.Red;
    public List<BlockColor> containedColors = new List<BlockColor>();

and in a monobehaviour, i can access position to move it at the start of the game:

if (runtimeData != null)
        {
            _gridMover.gridPosition = new Vector2Int((int)runtimeData.BlockPosition.x, (int)runtimeData.BlockPosition.z);
        }
        else if (data != null)
        {
            _gridMover.gridPosition = new Vector2Int((int)data.BlockPosition.x, (int)data.BlockPosition.z);
        }

or i can write to the data like this:

        runtimeData.containedColors = new List<BlockData.BlockColor>(_containedPrimaryColors);
elfin pike
#

Is it good practice to edit scriptable Object fields? Also it won't save between sessions

frail hawk
#

do you mean changing them at runtime

elfin pike
elfin pike
frail hawk
#

you asked if it is good practise to edit scriptable object fields, didn´t you

elfin pike
frail hawk
#

then you should ask google more often

cosmic dagger
grand snow
#

In editor changes persist!!!

elfin pike
grand snow
#

In a build changes are not kept so this cannot be used to "store" data long term

elfin pike
#

That's why using json

grand snow
#

Then just be aware of what happens if you modify a scriptable object asset

#

Best to avoid it during runtime/playmode

cosmic dagger
#

with a game build, editing an SO will not store the changes made, but inside of the editor, changing an SO field will KEEP any change made . . .

verbal dome
#

And it will only get saved in the editor if it gets marked dirty somehow

green arch
green arch
#

which can be serialized and saved to json

#

its just cleaner to have a runtime data copy and save those changes to the data of the object on session quit

elfin pike
#

So you save in SO and then on quite you save it as json?

grand snow
#

Sounds like you need 2 classes

#

Or to make a new instance at runtime to avoid messing up an asset

elfin pike
#

At that point, can't u use static class. Also, some stuff you can turn into json

blissful stratus
#

wtf is that?

blissful stratus
#

nvm i restarted unity

#

it doesnt end

swift crag
#

hmm, no other errors in the console (there's only one red 🛑 message)

wintry quarry
summer bear
#

Does anyone know how to use material property blocks for material switches?

#

My print value is updating properly, but the material isnt changing when I adjust my blink variable (it does for the others though)

#

which makes me think the reference is wrong or something else

#

a switch should be a true/false boolean, and an int should work as 0 and 1 for that, no?

swift crag
#

_TESTCOL_ON sure sounds like a keyword here

#

Changing keywords means you're loading a totally different shader variant

summer bear
#

This is the property list

swift crag
summer bear
#

Hmm let me try something then

swift crag
#

I know that Unity can toggle keywords based on material properties

#

your setup looks like you're meaning to use [Toggle]

#

(i have no idea how this interacts with Amplify)

swift crag
summer bear
#

Yea I took off the keyword name

#

so it should just be _TESTCOL

#

unfortunately its not working still

swift crag
#

This is still a keyword-based choice

#

lemme check the docs

faint agate
#

hey guys I have a weird problem that im not sure is fixable but ill ask.
I have a pistol
I shoot 3 times and each time I look more to the left
the probem is one of the shots are to the right.
I have a drawray for my raycast and when I look slightly to the left it sometimes bounces to the right.
is this a unity bug or fixable?

swift crag
#

okay, so you're using this

solar hill
summer bear
#

so is that why I cannot fetch the property with PropertyToID?

#

because the keyword is changing?

swift crag
#

Your actual property name is _TESTCOL, and that should have been fine

#

I think the problem is just that a MaterialPropertyBlock cannot cause keywords to change

#

So if you had directly set the int on the material itself, you'd have seen it working

summer bear
#

Which isn't ideal in my case, I would need to do a property block :<

swift crag
#

I would suggest replacing the Static Switch node with an If node

#

check if the _TESTCOL property equals 1

#

Keywords are appropriate for enabling or disabling large, expensive features

summer bear
#

So switchs arent ideal in my case

blissful stratus
swift crag
blissful stratus
swift crag
#

These messages get spammed when Unity is failing to free up some memory that it allocated

#

Sometimes that comes along with an error that prevented it from doing that

blissful stratus
solar hill
# faint agate

so tell me again, what behavior is happening, and what is the expected behaviour

summer bear
#

Im going to try an If node real quick

wintry quarry
blissful stratus
wintry quarry
#

this is the latest

solar hill
#

can you not

#

every time someone told you to stop shitposting you apologize and then continue to do it

solar hill
#

there si no right channel for that

summer bear
#

Thank you

swift crag
#

nice (:

summer bear
#

I wasnt aware Switch wasn't the play here

blissful stratus
swift crag
faint agate
swift crag
#

vs. a dynamic branch, which would be more like

#
if (_UseFeature)
  // foo
else
  // bar
#

both sides of the branch are compiled here, and the side you take depends on the property

solar hill
#

do you have a video?

faint agate
#

my clipping doesnt work 🙁

#

i have an idea one sec

summer bear
#

Yay! It works perfectly, thank you ❤️

vast matrix
#

For some reason when I try to Instantiate an object it spawns multiple objects instead of just one. Here is my code: ```using System.Collections;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Pool;
public class PotionSpawner : MonoBehaviour
{

public GameObject[] Potions;
public Transform Player;


private void Update()
{
    StartCoroutine(SpawnPotions());
}

IEnumerator SpawnPotions() 
{

        if (Input.GetKey(KeyCode.Escape))
        {
            // Spawn Potions around Player
            Instantiate(Potions[Random.Range(0, 2)], Player.position, Player.rotation);
            yield return new WaitForSeconds(5);
        }


}

}

wintry quarry
#

because it's in Update

vast matrix
#

oh ok

wintry quarry
#

As for your coroutine usage - it is pointless in your example

vast matrix
#

So I should change the If statement to update

wintry quarry
#

the fact you are doing this in a coroutine does nothing

#

other than adding complexity to the code

#

you are starting a new coroutine every single frame here

vast matrix
#

The coroutine is for later

wintry quarry
#

and then the coroutine immediately spawns something (if the key is pressed) and then contiunues to wait pointlessly for 5 seconds before it stops existing

wintry quarry
wintry quarry
#

Can you explain how you want this to work?

#

Do you want to spawn one object every time the player presses Escape?

#

if so:

void Update() {
  if (Input.GetKeyDown(KeyCode.Escape)) {
    Instantiate(...);
  }
}```
vast matrix
#

The goal of the code is to spawn an object every couple seconds, but I currently have it set to escape in order to spawn the items whenever

#

Otherwise I would have put it in a while loop

wintry quarry
#

So which one? Every frew seconds, or when the player presses escape?

#

Or both?

vast matrix
#

Currently the latter but I would like to get it to work inside the coroutine for the future

wintry quarry
#

For the latter I gave the example above

#

for the former you would do something like:

float timer = 0; // a timer variable to keep track of how much time has passed
float interval = 5; // time between spawns

void Update() {
   timer += Time.deltaTime;
   if (timer >= interval) {
     timer -= interval;
     Instantiate(...);
   }
}```
vast matrix
#

ok thank you

wintry quarry
#

I wouldn't recommend a coroutine here, as it's more difficult to make a consistent/accurate timer with one

#

it's also a bit more complex, for little benefit

faint agate
#

i also tried lerp and timedelta but the raycast keeping bouncing the wrong way im turning. the smoothing doesnt change it from bouncing the wrong way im a little lost

amber spruce
#

anyone got a really good 3d character controller?

#

idk if it matters but i want to be able to change the gravity for the player

naive pawn
radiant voidBOT
naive pawn
#

try googling around

green arch
green arch
#

always an instance of it

#

even better if you make a runtime copy and edit that

faint agate
# naive pawn !code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PocketPath : MonoBehaviour {
    private void Update() {
        //  Ray ray = cam.ScreenPointToRay(Input.mousePosition);
        Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f));
        float maxDistance = 200f;


        //Red ray in center
        Debug.DrawRay(ray.origin, ray.direction * maxDistance, Color.yellow);

    }
}

swift crag
#

I bet the raycast is being computed before the camera rotates

#

this will make it look like the raycast is angling slightly away from wherever you're trying to aim

faint agate
#

interesting I havent thought of that

faint agate
tacit prism
#

was reading the unity documentation looking for some explanation on a certain thingy but couldnt find much on it, or the documentation was just too hard for me to read at the moment

im working with button inputs and an input reader right now and im wondering where i could find some information on what the rest of the actions following context. could do

i see canceled, interaction, and i was told to do performed, but im wondering what others might do, as i feel they could probably be very useful

like i see one called time and i wonder if that has a count based on deltatime (if inserted)?

#

unity documentation kinda confuses me

wintry quarry
tacit prism
tacit prism
#

thanks!

wintry quarry
#

read the title of the link to understand what page it will take you to

faint agate
faint agate
#

any tips on how id go about it ?

lunar axle
#

how to get addressables label of this current gameobject that has the label c#

slender nymph
#

store the label at the time you initially retrieve the object, then you just get it from where ever you stored it

vast matrix
#

For some reason instantiate is spawning multiple copies of the same object. How do I get it to only spawn one copy. Here is my code: ```using System.Collections;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Pool;
public class PotionSpawner : MonoBehaviour
{

public GameObject[] Potions;
public Transform Player;


private void Update()
{
    if (Input.GetKey(KeyCode.Escape))
    {
        // Spawn Potions around Player
        Instantiate(Potions[Random.Range(0, 2)], new Vector3(Player.position.x + Random.Range(-5, 2), 0, Player.position.z + Random.Range(-5,2 )), Player.rotation);
    }
}

}

slender nymph
#

GetKey is true for every single frame that the key is down, perhaps you want a method that only returns true the first frame the key is pressed

vast matrix
#

Yes that would be what I am looking for

slender nymph
#

then consider looking at the documentation

vast matrix
#

I changed it to GetKeyDown and it worked perfectly thank you

sharp umbra
#

where do i start if im trying to learn how to make a 3d game in unity? (i tried googling for the answer but i dont really know what to look up)

slender nymph
#

!learn

radiant voidBOT
sharp umbra
#

huh i dont know how i didnt see that

lunar axle
slender nymph
#

i'm saying that where ever you initially load the asset via addressables is where you store the label in a variable because surely you're loading it via addressables and not just trying to reverse engineer an addressable label from something not loaded via addressables

lunar axle
#

or by naughtyattribute's button to do so.

#

so i kinda do need to reverse enginner

slender nymph
#

since this sounds like something you're doing purely in the editor it will actually be possible to do, it'll probably require using things from the UnityEditor namespace (which means you'll need to make sure to exclude that code from the build), but you can use the AssetDatabase to get an asset's guid from its asset path (which you can also get via the AssetDatabase), then with the guid it looks like you can call GetAssetEntry on your AddressableAssetSettings object to get the entry which will have the labels assigned to that object

mellow lance
#

Question:
I'm pretty new to Unity and i'm wondering how I would make some code that isn't linked to scripts attached to game objects?

I'm used to using Blazor and ASP.NET for personal projects, so trying to find the unity equivalent of making services/models/di/singletons/etc that aren't in game objects.

timber tide
#

just don't inherit from monobehavior

naive pawn
#

you may also want to consider SOs or singleton monobehaviours, depending on the specific needs of the task

mellow lance
#

so any services/models/etc i want to make just get thrown into the asset folder without any exceptions? Wouldnt anything i want running or saving info in the background still be reliant on gameobjects?

timber tide
#

well, if we want to think of singletons it's probably a static class versus monoclass versus scriptableobject

midnight plover
#

in the end its c#, make them static and access from anywhere. dont make them static, create an instance on runtime, whatever you like. GameObjecsts are just visual representations with properties that are still c# classes in the end. monobehaviour just brings the unity engine loop conveniently to your scripts

timber tide
#

static -> allocates when first called
mono -> exists on scene and may not exist when first called
scriptableobject -> doesnt exist in scene but is allocated similar to how resources are loaded

#

mono singleton is interesting such that it can serve as an entry point for each scene, meaning that each time you load a new scene that singleton can be a completely different instance.

naive pawn
#

i find that monobehavior singleton in an additive, persistent scene makes more sense and is easier to manage than having the singleton in every scene

timber tide
#

yeah there's a lot of ways to use them. Additive is useful for something like a object pool where you only ever want to allocate objects once throughout the game

sour fulcrum
#

i am slowly leaning towards scriptableobject singletons lowkey

elfin pike
#

how i understand, i cant serialize field in static class to reference SO?

sour fulcrum
#

So no inspector correct

elfin pike
#

how i can get reference of SO in static

north kiln
#

Generally you don't want something to be static, you may want to look into the singleton pattern

midnight plover
#

Noones gonna read a one liner log...

midnight plover
# elfin pike how i can get reference of SO in static

static can be used for methods that cover specific outputs for example. I use static methods for easing, that just output an eased value based on the start, end and progress time. But trying to access a "runtime" object reference from a static class is the wrong direction. You rather have, as vertx says, a singleton handling your reference and you couldhave a static class that extends your methods like with my easing example.

sour fulcrum
#

I mean it’s not necessarily the wrong direction, just depends on why they wanted it to be static

midnight plover
#

if you try to access a runtime object from a static class, that lives outside of your scene scope (in unity), you will most likely run into a hard coded reference to either a name, a file to be loaded by name/path or something else. I mean, sure, you CAN do that, but I would avoid it.

elfin pike
#

I hope, im not only beginner, who thought that all games need GameManager

sour fulcrum
#

Most do yeah

elfin pike
#

Dont see reason for my game to have. mostly it stores game states and sessionData

midnight plover
elfin pike
#

thats great, you can master anything. if you cant coding try to get good with somthing else in unity.

quartz wedge
#

One of the issues with game managers is that they usually end up as singletons or static objects. Statics and singletons are fine for certain things (loggers, helper methods), pretty much anything that doesn't contain state. The problem with the approach of singletons and managers for everything is that they seem convenient and as a "quick win" but as your project grows in size/complexity, you start to see the shortcomings of singletons. There is a software term called "technical debt", this is pretty much the concept of "kicking the can down the street", you are doing something short-term that can have larger implications as your project grows. This shows itself through statics and singletons in the form of your scripts.objects being "mutable", meaning they can change. If you have a lot of globals in your project that all systems can access/modify, you can no longer rely on the integrity of that state (as anything could change it). So I would say while statics/singletons seem very useful at first, they are difficult to maintain and scale as your requirements change. This is the negative impact that managers can have on a project (not all but most managers tend to be singletons and be responsible for a lot)

midnight plover
quartz wedge
#

Functionally there is no difference between a static object and a singleton in terms of use-case. You could say a singleton does provide a level of encapsulation (private constrcutor) but the only difference that really matters between the two is that a singleton is an object with a static member, meaning you can use inheritance whereas you cannot inherit from a static class. Beyond that they are the same and provide the same benefits (purely global state). The downside of a singleton is that every system can access it from anywhere. This makes it more conventient as your game logic is "centralised" but then you lack proper boundries how how your system connects and communicate with eachother, so you end up with one "god-object" that becomes the core dependeny on pretty much every system you create. Scripts should be small and have one reason to change "Single Responsibility". If you give your script a general name (GameManager.cs), then what is the responsibility? You could argue maintaining the state of the game world but because of the naming, it encourages your to overload its responsibilities which can be difficult to maintain in a larger project with growing/changing requirements. There is also the argument that it hinders testability but not many people follow TDD in game development

midnight plover
#

As this becomes a discussion of "whats the best approach" with different viewing points, I leave this conversation to not clutter up the channel more. But thanks for your insights and the short exchange of knowledge 🙂

naive pawn
quartz wedge
#

No problem, I didn't want what I mentioned to come off as "preachy" or "this way is the only correct way", a conversation came up regarding statics and I just wanted to offer some potential concerns with over-using them or at least highlight some of the downsides of them in larger projects

quartz wedge
glossy eagle
#

how can I duplicate a VisualElement? Because it doesn't seem I can use Instantiate

night raptor
real thunder
#

what approach would u use to determine if an enemy vehicle presses the player/someone and damage it like it's crushing?
no physics

real thunder
#

well there is kinda physics but agents don't really obey it

#

I can use a rigidbody and a trigger collider but how to filter out situations where, like, a tank is rotating and a player touches it's back turning away so they move the same direction and no damage should be done

night raptor
# glossy eagle okay thanks

Btw instantiate as in VisualTreeAsset.Instantiate, not Object.Instantiate which only works for GameObjects and Components

glossy eagle
#

yes, I just found that out, thanks hahaha

real thunder
#

I think I can use Physics.ComputePenetration to get a hit direction, some Raycast to get a hit position, use Rigidbody.GetPointVelocity with that position, calculate angle inbetween velocity and de-penetration, and if it's lower than like 60 do tick of damage

#

no, wait... kinematic rigidbodies don't really have velocities do they

elfin pike
naive pawn
#

"singleton" in unity and "singleton" in general oop have different implementations because of the context/environment

quartz wedge
# elfin pike What else singleton can be? I only know about instance in assets and scene

I think Chris was pointing out the fact that because a Singleton in Unity can inherit/derive from Monbehaviour, that gives you the added benefit of hooking up references via the inspector, since the Singleton script is a compoenent that can be attached to GameObjects in the context of Unity. So you get that extra sense of functionality from it being a component/Monobehaviour. This is something that you wouldn't get with a Singleton outside of Unity for example

elfin pike
#

I'm going to rewrite mission selection map. Had points throwing data at singleton on click. Now have to reference them to enable when level is unlocked

night raptor
real thunder
#

I gues for now I ll give up on that idea

humble summit
#

hello i hae this code that checks if all enemies are dead, and if they are the game win ui shows up

#

but it doesnt show up

#

my enemies are tagged with "Enemy"

wintry quarry
humble summit
wintry quarry
#

is it printing in the console?

humble summit
wintry quarry
#

If you're doing unity development without your console window visibile at all times, you are basically flying blind

wintry quarry
wintry quarry
#

You should add more logs

#

put another one inside EnemyDied

#

like:

Debug.Log($"An enemy died. There are {enemiesAlive} enemies remaining");```
#

See if that is printing as expected whenever an enemy dies

#

and make sure the number of enemies it thinks there are is accurate

humble summit
#

it doesnt print

wintry quarry
#

then you are never calling EnemyDied() when you kill an enemy

humble summit
#

on enemy died

wintry quarry
#

that's why nothing is working

humble summit
#

oh i think i know

#

oh im deleting enemies myself

wintry quarry
#

make sure this actually is running

humble summit
wintry quarry
#

you mean the Destroy()? That's irrelevant

humble summit
wintry quarry
#

that's the problem

humble summit
#

but then the code doesnt execute

wintry quarry
#

it's not going to run your code then yeah

humble summit
#

oh

#

well i hope this it

#

i need to test it

elfin pike
#

Hmm. Level manager rabbit hole

humble summit
#

i added a log ot the enemy healt script

#

and not even that shows up when the enemy gets shot and killed

nocturne hawk
#

Im ggonna spawn a prefab inside of an object but how can I control where the prefabs appear on the object?

elfin pike
nocturne hawk
elfin pike
nocturne hawk
#

huh?

elfin pike
elfin pike
humble summit
#

thanks

#

but i have found a new really bad bug i need to fix

#

god i hate programming

elfin pike
#

Writing cleaner and more stable architecture of code helps with bug spotting

humble summit
elfin pike
humble summit
elfin pike
nocturne hawk
humble summit
nocturne hawk
#

you could mabye have like kinda somehow said that

humble summit
#

and such

nocturne hawk
#

I think you responded to the wrogn guy💀

humble summit
#

oops

nocturne hawk
#

lol nw

elfin pike
elfin pike
real thunder
granite elk
#

Hello, i know this might not be a code related question, but how do I stay motivated in making my first real game? (A 3 months project) I feel bored when im making it...

real thunder
#

why did you start making it?

granite elk
# real thunder why did you start making it?

Because i wanted to explore game dev, i have learned unity for a month now and i know the basics, i have made 2 simple games and now i want to make a real game, something really playable, but im not motivated rn

verbal dome
#

Go play some good games and get inspired

granite elk
#

I already have the game idea (even tough its not the best but i will learn real gane things at least)

#

Its just that when I really start making it i get bored easily

rich adder
granite elk
rich adder
# granite elk It is already a simple game

..depends how you define "simple" make smaller wins you set yourself for the day.
or maybe take a break from it and come back to it when you're more inspired.
you can easily burn out

toxic ledge
#

i just finish the tutorial ypee

granite elk
elfin pike
rich adder
#

btw game design discussions overall should be in a thread in #💻┃unity-talk
this is a coding channel

granite elk
blissful stratus
#

how can i make spam key in my game?

#

you have to spam the key to pass

wintry quarry
#

and have some target number of times they have to press it

#

if they press less than the number, they fail

#

(within the time period, of course)

blissful stratus
naive pawn
#

make it continually decrease and add some to it every time you press the button

wintry quarry
#

what's a "spam bar"? You've underspecified the problem.

Sounds like maybe you want a continually decreasing number and each press increases it by a fixed amount

#

Quick example: @blissful stratus

float startingValue = 0.5f;
float failValue = 0f;
float winValue = 1f;
float decreasePerSecond = 0.5f;
float increasePerPress = 0.1f;
float currentValue;

void Start() {
  currentValue = startingValue;
}

void Update() {
  currentValue -= Time.deltaTime * decreasePerSecond;
  if (Input.GetKeyDown(KeyCode.P)) {
    currentValue += increasePerPress;
  }

  Debug.Log($"Current value: {currentValue}");

  if (currentValue <= failValue) Fail();
  else if (currentValue >= winValue) Win();
}```
limber stone
#

Hello, I am not certain if this is the correct channel to post in so please correct me if this is the wrong location so that I can move this plea for help.

I am currently trying to build a project that I have been working on for a while however whenever I do so it just is the default unity blue colour after a grey screen that fades away. In addition to that the frame rates exceed my frame cap of 240 which suggests to me that nothing is running and the resolution becomes 4:3 when the game should only be running in 16:9. Please could I get some help?

#

These are my build settings as well

#

And this is how it should look like at launch

wintry quarry
#

(make it a development build so it writes logs)

limber stone
#

alright

swift crag
#

you'll also see errors in-game in a development build

autumn quartz
#

Hey does anyone know where I can find any resources for making a 3D platformer in Unity?
I have the models and very basic stuff but idk where to find the right tutorials and ppl lol

slender nymph
#

!learn

radiant voidBOT
limber stone
slender nymph
#

!logs 👇 go to the documentation and find the player logs

radiant voidBOT
limber stone
#

This just makes things more confusing

#

I think for some reason it is rendering 1x1 pixels

#

I have no clue why

#

I changed the scene and it rendered the main colour from that scene which is red

#

Just this now

wintry quarry
#

do you ahve any code in your project that sets the game resolution?

#

I would search for that

limber stone
#

actually

#

possibly

#

that could be it

swift crag
#

what do you mean "main colour"?

limber stone
#

The most dominant colour on the screen

wintry quarry
#

maybe average or median pixel color 😛

limber stone
#

Sorry for the clarification

#

Yeah, median.

#

Also

swift crag
#

do you mean that you changed the background color of the camera?

vocal veldt
swift crag
#

if not, show what you actually did

limber stone
#

After changing the starting resolution in the player options the splash screen works but past that it reverts back to the issue

radiant voidBOT
vocal veldt
#

oops i didn't set the language

#

whatever

wintry quarry
#

or the camera object

vocal veldt
limber stone
wintry quarry
#

when you rotate the player, the flashlight will rotate immediately with it

#

since you're rotating only the camera for up and down, THEN your code with the lerp matters

swift crag
#

oh, so the flashlight is parented

vocal veldt
#

ohhhh

swift crag
#

i thought it might have been the "Point Light" object

#

that makes more sense

vocal veldt
#

got it thx

swift crag
#

If you want to keep it parented to the player, you could remember the rotation from the last frame and lerp from that to the goal rotation

wintry quarry
#

The answer here would be to either unchild the flashlight entirely and control its position/rotation via script, or to rearrange the hierarchy so there's a non-rotating object that is the parent of the flashlight but still moves

#

or yeah... hack it like Fen described

vocal veldt
#

i moved the flashlight object to be a child of Player

#

instead of the playerobject

swift crag
#

I think that makes more sense, yeah

wintry quarry
#

if Player doesn't rotate and PlayerObject does, that will work

vocal veldt
#

yes it worked

limber stone
#

So I think I found the issue

#

This is called at start and if you don't already have a save file

#

The settings.resolution variable just stays at the default 0

wintry quarry
#

that'll do it

limber stone
#

Same problem with the uncapped frame rate

#

Thanks for the help!

wintry quarry
#

I do like the idea of a 1x1 resolution game though

#

maybe a hackathon project

limber stone
#

mm!

#

That does sound like it could have some sort of potential

#

tbh

#

I don't know if the unity editor was rendering at 0x0 or if it rounded up to 1x1

#

I have no idea how 0x0 would work, so probably the latter

wintry quarry
limber stone
#

I feel like I remember there being some sort of game out there which was just completely black, it had no graphics and you had to rely on sound in order to do things therefore simulating blindness.

#

May have been a vr game, I am not entirely certain

#

Also, I have just applied a fix and tried commenting out all the code that could change the resolution

#

It still

#

Doesn't work

#

It seems that

#

Even if there is no path to this part of the code

#

Even if it is setting the resolution to something higher than 0,0

#

As long as the code exists it will do the glitch

autumn quartz
#

I followed a basic 3D platformer tutorial and my character isn’t detected as “grounded” when she is standing still
Is this a common issue

slender nymph
#

you likely followed it incorrectly. show the relevant setup and code if you want help

autumn quartz
#

hold on

autumn quartz
slender nymph
#

it's an unhelpful response until we actually know how you are performing the check. show the relevant details

solar hill
#

send the code here

radiant voidBOT
autumn quartz
#

my laptop doesn’t have discord so i had to use my phone for the pictures

slender nymph
#

ain't nobody trying to read those photos. share the code correctly

autumn quartz
#

uhhh ok

elfin pike
polar acorn
#

!code

radiant voidBOT
elfin pike
#

Debug.log isgrounded. Charactercontroller settings maybe not right

#

For love of god don't get components in update function. You can do it in start or awake

elfin pike
#

@autumn quartz Did you fix it?

faint agate
#

Hey guys I have a raycast that when I look slow left it tries to go right and back to left making this weird bounce back and forth effect. I tried smooth options but that didn’t fix it. My cam is in update and the ray is in late update. Someone recommended to change the execution order of the PocketPath script so that it always runs after the camera script but im a little lost on how to do that besides the late update method which didnt work. any help is appreciated

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

public class PocketPath : MonoBehaviour {
    [SerializeField] private float maxDistance = 200f; // configurable max distance for the ray

    private void LateUpdate() {
        // Create a ray from the center of the camera
        Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f));

        // Draw a yellow debug ray in the Scene view
        Debug.DrawRay(ray.origin, ray.direction * maxDistance, Color.yellow);
    }
}
gaunt cipher
rich adder
#

doubt thats the fix

gaunt cipher
#

same but that is how to change the execution order

verbal dome
#

What do you expect to see?

slender nymph
#

btw if you just want a ray from the center of the camera, you don't need to use ViewportPointToRay, just use the camera's transform.forward as the direction and it's transform.position as the origin

verbal dome
#

Slightly different because then it doesn't use the near plane position, but that often doesn't matter

faint agate
final trellis
#

I have a class that has a ushort value _amount and a string value _additionalOperations
inside the class, I have a short function called ExtractValue().

how would I have it read the string as a mathematical operation ( probably testing if its valid using regex ) and return it?
( example: _amount of 6 and _additionalOperations as "{_amount} / 2" should return with 3)

faint agate
#

you think it could be my camera jitter. I want to think that but the raycast is bouncing the opposite way im looking so im not sure

verbal dome
#

Is your camera a child of a rigidbody, does the rigidbody use interpolation, how's the rigidbody and camera being moved, etc.?

faint agate
faint agate
# verbal dome Is your camera a child of a rigidbody, does the rigidbody use interpolation, how...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerLook : MonoBehaviour
{

    [Header("References")]
    [SerializeField] WallRun wallRun; 

    [SerializeField] public float sensX = 100f;
    [SerializeField] public float sensY = 100f;
    [SerializeField] public float YPlayerStartDirectionY = 180f;
    [SerializeField] public float XPlayerStartDirectionX = 180f;

    [SerializeField] Transform cam = null;
     [SerializeField] public Transform orientation = null;
    public bool invertYAxis = false;
    public bool invertXAxis = false;

    float mouseX;
    float mouseY;

    float multiplier = 0.01f;

   public float xRotation;
   public float yRotation;

    private void Start() {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
        yRotation = YPlayerStartDirectionY;
        xRotation = XPlayerStartDirectionX;
    }

    private void Update() {


            mouseX = Input.GetAxisRaw("Mouse X");
            mouseY = Input.GetAxisRaw("Mouse Y");

        yRotation += mouseX * StagesSenseManager.Instance.SenseValue * multiplier;
            xRotation -= mouseY * StagesSenseManager.Instance.SenseValue * multiplier;

        xRotation = Mathf.Clamp(xRotation, -90f, 80f);



        cam.transform.rotation = Quaternion.Euler(xRotation, yRotation, wallRun.tilt);
        orientation.transform.rotation = Quaternion.Euler(0, yRotation, 0);


    }

}
slender nymph
#

assuming orientation is the rigidbody, you are breaking the interpolation by modifying its transform which is causing jitter

verbal dome
#

I think it's a "camera container" object

#

Seen many tutorials teach that lately

#

Or maybe it's the chatbots

faint agate
verbal dome
#

How do you move the rb? What boxfriend said is the usual cause

faint agate
# verbal dome How do you move the rb? What boxfriend said is the usual cause

I want to say its this. this is in update

        _movementDirection = InputSystemHandler.Instance.PlayerInputActions.Player.Move.ReadValue<Vector2>();
        horizontalMovement = _movementDirection.x;
        verticalMovement = _movementDirection.y;

        moveDirection = orientation.forward * verticalMovement + orientation.right * horizontalMovement;


final trellis
verbal dome
#

Also pro tip, use a low time scale to debug jitter/interpolation issues

slender nymph
faint agate
# slender nymph that does not *move* anything, this is just calculating the direction and distan...
    void MovePlayer() {
        if (isGrounded && !OnSlope()) {
            rb.AddForce(moveDirection.normalized * moveSpeed * movementMultiplier, ForceMode.Acceleration);
        } else if (isGrounded && OnSlope()) {
            rb.AddForce(slopeMoveDirection.normalized * moveSpeed * movementMultiplier, ForceMode.Acceleration);
        } else if (!isGrounded) {
            rb.AddForce(moveDirection.normalized * moveSpeed * movementMultiplier * airMultiplier, ForceMode.Acceleration);
        } 
    }

slender nymph
#

and how do you rotate it

faint agate
slender nymph
#

the rigidbody

faint agate
faint agate
#

thats in start

slender nymph
#

and you are absolutely certain you aren't rotating its transform? when i said "rigidbody" i was referring to the entire rigidbody object

faint agate
#

I dont believe so. I just played the game and moved around while player selected and didnt see rotation change

#

the only thing rotating is my camera holder

faint agate
slender nymph
#

that would only be the case if the first part of that message was true

faint agate
#

i think I fixed it

rich adder
faint agate
#

The ray is finally smooth cause of that thank you I switched it to cam forw and it works now. Much appreciated. Ive been stuck on this bug for so long thank youuu

final trellis
#

id have to look into this

#

from a surface level it looks like what I need, if not a bit overkill

#

i think

rich adder
#

yeah probably lol

final trellis
#

yeah its what im looking for but waaaayyyyy overkill

rich adder
#

maybe start with some Regex for safely parsing math characters & then do the evaluation ?

final trellis
#

i also wanna add my own custom little thingies ( like being able to type R(a, b) and it gives a number between A and B )

#

so i think regex would also help with that i guess

rich adder
final trellis
#

aigh, i wont forward my original question bc im expanding it a bit

verbal dome
#

Not sure if you can add custom operators/functions tho...

final trellis
#

oh hell yeah

final trellis
#

i'd have to parse the custom stuff first

#

but i guess the actual evaluation parts solved! just need to do crazy shit with regex i think???

verbal dome
#

The ExpressionEvaluator code is readable with IDE if you go to the source

#

Maybe you can use it as reference

terse saddle
#

yo, can someone help me? im making a 2d videogame but the collitions just dont collition

verbal dome
#

(I'm not a lawyer)

vast matrix
#

For some reason my Camera follow code randomly broke and completely stopped working despite it working perfectly before. Here is my code if someone could help me find the issue: ```using UnityEngine;

public class PlayerCam : MonoBehaviour
{
public float sensX;
public float sensY;

public Transform Orientation;

float xRotation;
float yRotation;

private void Start()
{
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
}

private void Update()
{
    // Get mouse input

    float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
    float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;

    yRotation += mouseX;

    xRotation -= mouseY;
    xRotation = Mathf.Clamp(xRotation, -90f, 90);

    // Rotate cam and orientation
    transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
    Orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}

}

verbal dome
verbal dome
terse saddle
#

i guess there is an obvious error im not able to see

#

but according to chat gpt the script is rigth so i dont know

frosty hound
#

Guess it's unsolvable if chatGPT can't figure it out.

#

Possibilities:

  1. This script isn't actually on your player
  2. You have too low (or no) speed value. You shouldn't use default values for public fields as they're overridden by the inspector.
verbal dome
#

Saw the first screenshot, looks like you are using a kinematic rigidbody on the character

#

If you do that then you are expected to do your own collision checks

terse saddle
#

the player can actually move

#

the problem is that it passes through objects

frosty hound
#

I didn't realize your issue was collision related

#

Osmal's point stands though

terse saddle
#

it doesnt work neither

verbal dome
#

With dynamic you need to use rigidbody.linearVelocity or AddForce to move it

#

Not MovePosition

terse saddle
#

ohhhhhhhhhh

#

thanks man

night raptor
#

Actually iirc MovePosition is fine with the 2D physics engine

#

Moves the rigidbody to the specified position by calculating the appropriate linear velocity required to move the rigidbody to that position during the next physics update

#

Same does not apply for 3D though

verbal dome
#

Yeah, though the doc also says

Note: MovePosition is intended for use with kinematic rigidbodies.
Still unsure what the limitation here is though, haven't tried it too much

#

I think the kinematic collision wasn't working because this full kinematic contacts wasn't enabled on the RB 🤔

night raptor
#

Sounds weird. It also states:

If the rigidbody is kinematic then any collisions won't affect the rigidbody itself and will only affect any other dynamic colliders.
Sounds like either would be fine. Last time I tried it worked fine, using velocity would probably be safer option though just to be sure

verbal dome
#

And I can't seem to get a kinematic RB2D to collide with anything when using MovePosition 🤔

#

So from everything I see, it doesn't automatically apply collisions forces to stop itself on any collision

night raptor
#

That's odd. Same with Continuous Collisions? Of course with Discrete you can set it behind a wall and it will teleport there

#

Never really done 2D games myself but I'm pretty sure I did test this couple years ago and it did collide correctly.

verbal dome
#

Yeah, tried with CCD, doesn't work

livid anchor
#

I have a small but annoying issue with events.
I have class that just has static actions, and I can attach/listen to such actions, but not trigger an event. I have an error saying the action does not exist in the type...

public static class RunnerEventSystem
{
    public static Action<float> OnPlayerJump;
    public static Action<float> OnPlayerOutOfFuel;
}

private void Awake()
{
    //That's okay
    RunnerEventSystem.OnPlayerJump += Jump;
}

private void Awake()
{
    //That's not okay (ignore the fact that it's in the awake)
    RunnerEventSystem.OnPlayerJump? Invoke(_jumpDuration);
}

unreal veldt
livid anchor
#

It was indeed a small issue -_-

unreal veldt
#

Haha yeah, those are the worst ones

#

C# is super picky about tiny syntax details, and ?.Invoke() is one of those things that’s easy to mistype when you’re moving fast. One missing . and suddenly the compiler acts like the whole thing doesn’t exist.

midnight plover
#

If you running into this and your IDE isnt telling you the error, you might have not setup your IDE correctly.

#

!ide

radiant voidBOT
north kiln
#

static events 🤕

vital sun
#

This is probably the best channel for this so here we go

#

I want to implement Lua scripting support for my project and I would like to ask for some recommendations as to which library/store asset would be the best for my usecase

#

The idea is that the scripts would be read at runtime and each script file would be a definition of behavior for singular things like events, skills, etc

#

Ideally being able to read properties and call methods on specified unity gameobjects with as little friction as possible

north kiln
#

If it's their own project then it's fine

vital sun
#

I'm not trying to mod someone's game if that's what you are implying

midnight plover
midnight plover
midnight plover
#

I guess, it depends on how complex you targeting your system to be. This is a simple approach for a simple task, could be extended but might not be the correct solution if it gets way more complex.

vital sun
#

The exact complexity is something that I have yet to determine, as this project of mine is in the very early stages

heavy rampart
#

guys which one

naive pawn
heavy rampart
#

oh alr

#

i mean i mostly use vsc I'm new to game dev haven't used vs for a while xddd

vital sun
#

Either way I first need to implement anything and experiment with it which leads back to my question about library/store asset recommendations as to what should I use for Lua support

errant breach
#

Hello !
Im trying to access the __SequenceChangeLevel__, i've created a universal trigger zone that usually can access gameObject's script's function but for the first time, it doesn't work. The __SequenceChangeLevel__cannot be found nor executed.

Am i doing a mistake ?

#

In this other example, i do manage to access the __activate__ function so i don't know what im doing wrong.

    {
        Invoke(nameof(Activation), timeBeforeSpawn);
        AddEnemyCount();
    }```
sour fulcrum
#

i know it's not the question but whats with the underscores

#

whats in here

#

also another thing that doesnt matter but most people don't put scripts in the name of their script, it's redundant

midnight plover
#

The part with "No function" usually shows you all public methods that have one param, like a float, string or boolean if the event on your inspector class supports it. But there is by default none for multiple params. You gotta create that custom editor for yourself afaik

errant breach
errant breach
midnight plover
errant breach
midnight plover
# errant breach Alllriiggghhttt... Thank for the explanations ! It so much better now that i und...

I have to extend my explanation, just to not give half baked information. So the "no function" part shows your functions, when for example a UI Slider event supports the float value. So instead of hard typing it in the even,t you can chose the dynamic one and it will call it with the slider event (just for example). But you can still get the method from the lower alphabetically sorted part of the list, where you can type in the float you want to pass in too. Just to make sure, you know both ways how your public methods are handled with one param 🙂

elfin pike
#

gettings "IOException: Sharing violation on path".no idea why. how i understand error, something else is accessing file, but only one class instance, has access to file

#
        File.WriteAllText(SavePath, json);```I have same setup in other classes, but they dont throw error
humble summit
midnight plover
elfin pike
midnight plover
# elfin pike Path is allowed, I created it in class

Well, the error says, something is not allowed on your path. So you are trying to access "something", thats not allowed. Maybe you are trying to write a file while reading it, maybe you got the wrong path in and tried to save somewhere on the system.

elfin pike
#

Maybe I have to close it after writing

midnight plover
elfin pike
#

I can we also load function, which is also 2 lines

midnight plover
elfin pike
#

Load called in start of class life time. Save called in end of it at destroy

midnight plover
elfin pike
noble ore
#

not a coding question but can someone tell me how to get rid of this empty area, its annoying me

midnight plover
hexed terrace
#

That area is like that because you've focussed on something large, and then moved closer

#

Select the green plane, press F

noble ore
#

pressing f didnt really fix it either

midnight plover
#

Not my Settings… its your scene view settings cutting off with occlusion culling. Play around with it

noble ore
#

is it something with the zoom or something, it just shows 0.76x for some reason

#

i see

wintry quarry
charred monolith
naive pawn
#

you click the button that says iso

#

i'm still not really sure what the expected behavior is tbh

hexed terrace
naive pawn
#

ah

elfin pike
#

Looks like I'm correct I open file but don't close it

wild peak
elfin pike
#

Looked up in "learn microslop com" about "FileSystem.WriteAllText Method". It says, that file should close after function finishes

swift crag
#

the near clip plane is at 17.7 meters

#

so anything that's closer to the camera than that will not be rendered

#

turn on "Dynamic Clipping" and then hit F to focus on the object

#

this will adjust the clipping planes to something sensible for whatever you have selected

swift crag
#

occlusion culling is used to disable renderers that are completely covered up by another renderer, and that only happens in the scene view when you have the Occlusion window open

elfin pike
elder hearth
#

Why isnt my ray shooting out the center of the camera holder? OR even the camera. Its not even the right direction.

cs
 RaycastHit hit;

 if (Physics.Raycast(transform.position, transform.TransformDirection(CameraHolder.forward), out hit, 5))
 {
    Debug.DrawRay(transform.position, transform.TransformDirection(CameraHolder.forward) * hit.distance, Color.yellow);
 }
keen dew
#

Is this script on the camera holder? Does CameraHolder refer to a transform component? What's the purpose of the TransformDirection?

wintry quarry
#

It should be:

Physics.Raycast(CameraHolder.position, CameraHolder.forward, out hit, 5)``` and
```cs
Debug.DrawRay(CameraHolder.position, CameraHolder.forward * hit.distance, Color.yellow);```
dapper field
#

how should I store persistent data if the gameobject won’t exist sometimes? Asking because if I’m reading correctly, File.WriteAllText() will overwrite anything I have saved in another file if I can’t call that gameobject’s save function, then it won’t have anything later.
(I don’t have access to exact code right now, I’m planning out in pseudocode while at school and kinda wanna know so I don’t run into issues later)

As in, if I have a float that a script will use, but the script only exists sometimes, should I use another class, a modifiable scriptable object with the fields, a different save file, etc, if that float should save its state between all instances of that script

keen dew
#

Surely the game doesn't need to save the data of a gameobject that doesn't exist at the time the save is made

dapper field
#

i can provide better examples of what i’m trying to accomplish in about 3 hours-

keen dew
#

If you need to transfer modified data from one scene to another you can save it when the scene ends and restore when returning

dapper field
#

the data is different for each of the scenes
the original one needs its original data
if that makes sense
but the script doesn’t exist and I can’t call the save anymore

#

I also learned how to save like 2 days ago and its barely functional so maybe i’m misunderstanding how it works/ i just did it wrong

#

i’m just gonna re-ask the question in 3 hours, or maybe ill figure out between then. Sry if my bad code is giving you an aneurism

hexed terrace
#

You save the required data when it is about to be destroyed, not at some random point in the future when that data doesn't exist anymore

dapper field
hexed terrace
#

and save in such a way that doesn't overwrite data

#

either multiple files, or a json or something that adds data to it rather than completely writing a file every time

dapper field
keen dew
#

You should have one save manager that handles making saves anyway, so instead of having each object handle saving independently they tell the save manager what to store and the save manager handles it centrally

hexed terrace
#

don't see why it would be, probably depends on the situation

short gust
#

is there any "fast" method of getting all types with attribute at runtime? I know about edit time TypeCache class thingy, but what about runtime? just iteration over assemblies is utterly slow even if filter out Unity/System assemblies before it

#

I need it do it once btw, but also want to avoid hickup on startup of the runtime when it do the iteration

slender nymph
#

what is the purpose of this? because a source generator might be a better option than doing it at runtime

cosmic dagger
#

i'd rather have this beforehand, not during runtime . . .

short gust
#

I don't have a "runtime only" criteria btw, like I'm open to any solution to look up in google. I wrote about runtime gathering and iteration over assemblies only because I don't know anything else or how to do it in any better way, lol.

I'm writing something like attribute based "DI"-like thing just for learning sake and my own pet project usage.

swift crag
#

You should be able to do it once and hang onto the results after that, of course

slender nymph
short gust
pseudo summit
#

Hey

#

So uh i was following GMTKs tutorial on a flappy bird game, and in the update function thing he used instantiate and delayed it by setting a timer to 2 and then added time.Deltatime to t every other frame and reset back to 0 afrer the spawning. But when i increase the number from 2 to like anything the delay doenst change between the pillars spawning

polar acorn
#

Are you changing it in code or in the inspector

pseudo summit
#

in visual studio

polar acorn
# pseudo summit In code

the code defines the default values. The entire point of the variables in the inspector is to override the default values.

#

change it in the inspector

rich adder
#

when you add script on a gameobject, once the value is Serialized by unity with public or [SerializeField] private the inspector takes precedence.
changing in the code will have no affect unless you were to reset the script or re-add it.

swift crag
#

the C# field initializers provide the initial value for the field; however, Unity then plugs its own values into those fields after creating the object

#

therefore, the field initializer only matters:

  • when creating a brand new object, if the field is serialized
  • for non-serialized fields
jovial heron
#

i have anystate connected to 3 animations one if them is "hurt" animation it uses a trigger variable after the paramater triggers and the animation plays the transition has exit time but it is skipped if another anystate condition is triggered how do i make the transition's exit time unskippable without turning the hurt paramter in to a bool

swift crag
#

It's not very useful for anything non-trivial

#

my VRChat brain said "oh, use a parameter driver to set a parameter when you enter the pain state, and then reset it when you exit the pain state"

jovial heron
swift crag
#

Consider using Animator.Play() to forcibly enter the pain state, rather than using an Any State transition to get there

#

this does mean that your animator now depends on a script to work the way you want it

#

(well, it already did for parameters, duh, but now it requires more than parameters)

solar hill
#

do you need assistance with something?

#

this is a help channel.

#

yes

queen adder
#
using UnityEngine;

public class CharControllerScript : MonoBehaviour
{
    public float speed = 5f;
    public float jump = 2f;
    public float gravity = -9.81f;

    private CharacterController cc;
    private Vector3 velocity;

    float maxReach = 300;
    public GameObject Bed;
    public GameObject TimeManagerObj;


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

    void Update()
    {
        Vector3 move = transform.right * Input.GetAxis("Horizontal") + transform.forward * Input.GetAxis("Vertical");
        cc.Move(move * speed * Time.deltaTime);

        if (cc.isGrounded && velocity.y < 0)
        {
            velocity.y = -2f;
        }

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

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

    void FixedUpdate()
        {

        // Will contain the information of which object the raycast hit
        RaycastHit hit;

        // if raycast hits, it checks if it hit an object with the tag Bed
        if (Input.GetKeyDown("e"))
        {
            if(Physics.Raycast(transform.position, transform.forward, out hit, maxReach)     &&
                    hit.collider.gameObject.CompareTag("Bed"))

            {
                Sleep();
            }
        }
        
    
    }

    void Sleep()
    {
        TimeManagerObj.GetComponent<TimeManager>().totalSeconds = 86400f;
    }
    
}```



this is my character controller, i have assigned a cube the "Bed" tag, and the raycast and "Sleep()" function work but only on one specific corner of the bed obj for some reason ??
wintry quarry
slender nymph
#

make sure your raycast isn't hitting something else

#

also that

wintry quarry
#

second - yeah. split up the if conditions and add a log showing what you actually did hit, if anything

wintry quarry
#

e.g.

if (Raycast(...)) {
  Debug.Log($"Hit {hit.collider.name} with tag {hit.collider.gameObject.tag}");
  if (hit.collider.gameObject.CompareTag("Bed")) {
    // hit the bed
  }
}
else {
  Debug.Log("hit nothing");
}```
vast matrix
#

For some reason this code is rotating the Player along the wrong axis. Could someone help me fix it because I don't know what's wrong: ```using UnityEngine;

public class PlayerCam : MonoBehaviour
{
public float sensX;
public float sensY;

public Transform Orientation;

float xRotation;
float yRotation;

private void Start()
{
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
}

private void Update()
{
    // Get mouse input

    float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
    float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;

    yRotation += mouseX;

    xRotation -= mouseY;
    xRotation = Mathf.Clamp(xRotation, -90f, 90);

    // Rotate cam and orientation
    transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
    Orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}

}```

naive pawn
#

it's already per frame

vast matrix
#

Yeah idk why I used it

naive pawn
#

is Orientation a child/parent of this object?

vast matrix
#

yes it is

naive pawn
#

which one is it

vast matrix
#

it is a Child of the "Player" gameObject

naive pawn
#

...i don't know what that is in relation to this object

#

i'm not looking over your shoulder

vast matrix
#

Its a child of the gameObject this script is attached to

naive pawn
#

so it's the current gameobject that's being rotated incorrectly as well?

vast matrix
#

Yes

naive pawn
#

usually (as far as i've seen) you would have the camera as a child of the player, and you would have the player yaw and camera pitch separately

#

(probably not directly related to your issue, just commenting on the setup)

#

is the player rotated to begin with, in edit mode?

vast matrix
#

No

naive pawn
#

you could describe/show how exactly it's rotating incorrectly

vast matrix
#

It is rotating the gameObject along the X and Z axis instead of the Y axis. (Ie its rotating the player vertically instead of Horizontally)

naive pawn
#

the values in the inspector show the x/z values changing?

vast matrix
#

Yes.

naive pawn
#

is the player a child of anything else?

vast matrix
#

It is not a child of anything

vast matrix
#

Let me see if another script is causing this issue.

#

It is not because of another script

#

Im just gonna rewrite the code in order to find out where this issue is occuring

dreamy lance
#

anyone know how i could make this cinemachine camera only move when the player is leftclick and dragging instead of any time the mosue moves ?

slender nymph