#archived-code-general

1 messages Β· Page 444 of 1

ivory fjord
#

Holy... CustomEvent.Trigger(target, eventName); works.
How do you call events in Visual Scripts from C#?

thick terrace
#

most events go through the event bus so you just need to register/trigger for the right name to use it for your own code

ivory fjord
#

All right, thank you both @thick terrace @hexed pecan I am coming from Unreal Engine and Visual Scripts / Blueprints seem to be much more developed there... Thank you!

steady bobcat
#

visual scripting is kinda new so not suprised its half baked

thick terrace
#

there's third party ones that can do more stuff like unreal (generating totally new classes etc) but the official VS package is fairly minimal

regal crag
placid edge
#

i got it to work πŸ₯³
just had to set an if statement that resets the velocity of the rb if it falls under the speed variable.

vestal arch
#

tfw you accidentally use a unity message as a normal method's name πŸ₯²
now to come up with a new name.....

ivory fjord
#

What am I doing wrong?

vestal arch
#

no...? why'd you assume it was you lol

swift falcon
#

can someone tell me

#

why its rotated the wrong direction

#

im using the correct export settings

#

its only rotating the blender direction when im removing the planes aka leaves

somber nacelle
wild nebula
#

How to set it up manually by myself?

hexed oak
#

how tricky is it to modify a value in a prefab variant?

vestal arch
#

it.. isn't?

hexed oak
#

If I can get the prefab variant and then just want to change a color or int value in the variant is that feasible

vestal arch
#

yes

hexed oak
#

via code I should say

vestal arch
#

of the prefab?

hexed oak
#

yes

#

prefab variant

vestal arch
#

yeah that's fine

#

i mean, you can do it

#

is this for editor code?

#

or what are you trying to do?

hexed oak
#

yeah editor code

vestal arch
#

ah

hexed oak
#

just a tool to allow people to configure UI objects in the editor

vestal arch
#

yeah a prefab is just a gameobject captured into an asset, you can modify properties of it or its components just fine

hexed oak
#

sweet, thank ye

steady bobcat
#

use prefab utility to open the asset, modify it and then save it after

unkempt meadow
#

is there really no way to pause an animation or set the speed of a particular state via code?

hexed pecan
#

Select a state and look in the inspector

#

Set the parameter and change that from code

unkempt meadow
#

aaaah ok thank you

#

that's really clunky

#

I would have expected a pause and resume method but ok if it works

unkempt meadow
hexed pecan
#

Naturally yes

jolly stratus
#

guys, i am using text mesh pro and i imported a font, but its showing this random letters. the only working font is, Liberations Sans SDF which was preloaded. im using Unity 6

somber nacelle
#

this is a code channel

jolly stratus
somber nacelle
sturdy holly
#

Im using unity 6000.1.0f1 and I just noticed my gizmos are not rendering in game view (when I have gizmos enabled and ticked on) tried restarting but no change

vestal arch
#

Gizmos are used to give visual debugging or setup aids in the Scene view.

sturdy holly
#

yes they are, you can enable it

#

I can do it in 6000.0.37f1 right here next to it

#

its this in gameview mode

#

I guess many dont realise its been a thing for a long time but seems broken in the supported version

hexed pecan
#

That has solved similiar bugs for me

sturdy holly
#

will give that a shot

#

no change, very odd

hexed pecan
#

What gizmos are you expecting to see exactly?

#

(is this even a code question?)

sturdy holly
#

its just a wiresphere, I can see it in scene view mode but I would usually be able to see it (when toggled) in game view too its just not working in this version

#

def something wonky with this ver for me

naive swallow
#

Can you show the code for it? Maybe it's not where you expect it to be? Maybe something changed around it and the sphere isn't getting drawn?

#

Or is it that they are visible in scene mode

#

but not in game mode when enabled?

sturdy holly
#

I can see it fine in scene view, its the game mode thats not showing them when enabled

#

I have an older version editor side by side (last LTS) and it works in that

naive swallow
#

Okay, not likely code related then

#

Definitely sounds like it could be a Unity !bug

tawny elkBOT
#

πŸͺ² To make bug reporting as quickly as possible, we made a bug reporting application for you. When running Unity choose Help->Report a Bug in the menu, or you can access it directly through the executable in the directory where Unity is installed. It will also launch automatically if you experience a crash.

πŸ“ If your bug report is to do with Documentation, either an error, typo, or omission, you can report it by scrolling to the bottom of the page where you found the issue and click β€˜Report a problem on this page’!

πŸ’‘If your report is to do with a new feature idea, you can check the Unity Product Roadmaps page to see if your idea has already been planned.

For more complete instructions on how to report bugs, access: https://unity3d.com/unity/qa/bug-reporting

naive swallow
#

I'd try the ol' "I have no idea what the fuck unity is doing" solution of deleting the Library folder and restarting?

hexed pecan
#

I'd also check if the bug is present in a fresh scene

#

And maybe toss a debug.log into the gizmo drawing method you are using

sturdy holly
#

yeah its just a simple Gizmos.DrawWireSphere(transform.position, 0.25f); in the OnDrawGizmos. nowt exotic - will try in a fresh scene but its not really got much in yet

#

same in blank scene, reported bug anyhow

hexed pecan
#

Did you try adding the log, just out of curiosity

#

And to narrow it down a bit

sturdy holly
#

I opened it in the LTS and it works as expected

#

its just the gameview in supported not working correct with gizmos it seems

#

there is nothing to log, it gets called - can be seen in scene view

somber nacelle
#

ensure it is still being called when you are viewing game view by logging

naive swallow
#

If the actual object drawing the gizmos gets culled due to being out of frame or occluded, do the gizmos it draws get culled as well?

#

Maybe due to some different settings the play camera is culling it? Maybe it's on a layer the game camera can't see?

devout knoll
#

i'm trying to make a system in unity which takes two meshes, and takes the overlapping components making it a seperate mesh which is the volume intersection of each other

i'm using LibCSG library to attempt and achieve this, however it hasn't worked out. Does anyone have any say starting point to start making this? there can be any number of "LIGHT_" components, and they can only intersect with other "LIGHT_" components at any time, as they are movable.

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

public class LightIntersectionManager : MonoBehaviour {
    public Material intersectionMaterial;

    private List<CSGBrush> lightBrushes = new List<CSGBrush>();
    
    private CSGBrushOperation CSGOp;
    private CSGBrush IntersectionComponent;

    void Awake() {
        CSGOp = new CSGBrushOperation();
        IntersectionComponent = new CSGBrush("IntersectionComponent");
        
        foreach (var mf in FindObjectsOfType<MeshFilter>()) {
            if (mf.gameObject.name.StartsWith("LIGHT_")) {
                CSGBrush lightBrush = new CSGBrush(mf.gameObject);
                lightBrush.build_from_mesh(mf.gameObject.GetComponent<MeshFilter>().mesh);
            
                lightBrushes.Add(lightBrush);
            }
        }
    }

    void Update() {
        /*
         * Check for intersections between all objects with "LIGHT_" in the name
         * create a mesh which is the intersection between any two light objects
         * give the mesh: intersectionMaterial, kinematic frozen rigidbody, mesh collider
         */
    }
}
hexed pecan
#

FYI, that is called a boolean AND operation or boolean intersect operation

#

In case you want to search for other solutions

devout knoll
#

boolean intersect i believe

#

most solutions i found of people attempting the same use CSG libraries such as this one

latent latch
#

Godot has an implementation of that somewhere in the source probably

devout knoll
#

i also heard of triangle-triangle checks im not sure if that would be better

hexed pecan
#

Are these 2D (planar) meshes or 3D?

devout knoll
#

3D

hexed pecan
#

Triangle-triangle check is kinda vague

devout knoll
#

i can send an image to better illustrate my goal

hexed pecan
#

In any case you want a boolean op

latent latch
#

Wonder what blender does, but it's usually messy and populates a ton of verts in the end

hexed pecan
#

Which might/probably does use some triangle intersection checks

devout knoll
#

that little triangle bit which is inside the yellow part would make a mesh ideally

#

the cube is movable

devout knoll
hexed pecan
#

Probuilder also has a boolean tool but it's experimental probably forever because it seems that no one can make fully robust boolean operations

#

Not sure if it's exposed in an API anywhere

latent latch
#

good concept though for level building and blockouts

#

assuming you can clean it up

#

probuilder could really integrate more of it

#

I wish I could use that tool more, but it seems to brick itself if do some bad operation

night harness
#

Just out of curiosity, since accessor modifiers aren't really a thing by the time stuff compiles, Is there anyway I could brute force inheriting from some of Unity's sealed components?

#

Probably wouldn't be for any long term solution just playing around with things

sturdy holly
#

I return, I fixed the gizmos not appearing in game view.. it happens when DX12 is selected

#

switch to 11 and it shows... annoying but ok

#

(in the supported release)

somber nacelle
#

make sure to submit a !bug report

tawny elkBOT
#

πŸͺ² To make bug reporting as quickly as possible, we made a bug reporting application for you. When running Unity choose Help->Report a Bug in the menu, or you can access it directly through the executable in the directory where Unity is installed. It will also launch automatically if you experience a crash.

πŸ“ If your bug report is to do with Documentation, either an error, typo, or omission, you can report it by scrolling to the bottom of the page where you found the issue and click β€˜Report a problem on this page’!

πŸ’‘If your report is to do with a new feature idea, you can check the Unity Product Roadmaps page to see if your idea has already been planned.

For more complete instructions on how to report bugs, access: https://unity3d.com/unity/qa/bug-reporting

sturdy holly
#

aye I did earlier, going to update it if I can

night harness
#

Just looking for a general vibe check I guess but for a prototype im making I wanna make a fairly generic object viewing/setting window for content in the game that's going to be pretty similar to Unity's inspector. Right now the way im thinking about doing it is having each piece of content provide a list of boxed paired getters and setters for the values they want shown and changed and then check the type of the value and see if I have any UI options that can support editing that value. Am I kinda on the right track here?

https://gist.github.com/IAmBatby/06f7f194aa5c091f6008e70812f2d5f8

Gist

GitHub Gist: instantly share code, notes, and snippets.

#

I've thought about using some kinda boxed/wrapper class for the values I want to showcase directly that's serialized but holding off for now. I might need to pivot for that if i get into needing to provide extra data like display text and whatnot

wild nebula
#

I am generating UI elements procedurally, so I'm not sure how this is done

quartz folio
#

titleDisplay["fromLevel"] = new IntVariable { Value = fromLevel };

wild nebula
quartz folio
#

or preferably
titleDisplay.Add("fromLevel", new IntVariable { Value = fromLevel });

fiery steeple
#

I really struggle to have a working dayCycleSpeed using the dayCycleSpeed field in the VoxelPlayEnvironment class but it doesn't work, it always goes too fast. So how can I fix that please ? Maybe my formula in TIME_INCREMENT_PER_SECOND is wrong, if that's the case what's the correct formula please ? πŸ€”

leaden ice
#

What does a "daycycle speed" of 1 mean? What about 5?

#

I will say one issue i'm seeing for sure here is that you're not using Time.deltaTime in Update so everything is going to be framerate dependent - i.e. it will run faster with a faster framerate, which is generally not desirable

#

you're doing += TIME_INCREMENT_PER_SECOND every frame

#

pretty sure you want to multiply by deltaTime there

fiery steeple
leaden ice
#

that will make it actually behave as though it's "per second" and not "per frame"

fiery steeple
leaden ice
#

If you want 1s = 1m then TIME_INCREMENT_PER_SECOND should be 60 (60 seconds in game per 1 second IRL).

And yes you need to multiply bt Time.deltaTime

leaden ice
fiery steeple
leaden ice
#

should just be 60

#

not 1/ 60

#

and you shouldn't have dayCycleSpeed being used in update

leaden ice
#

just timeOfDay += Time.dletaTime * TIME_INCREMENT;

leaden ice
#

there's no sence factoring it in again

fiery steeple
#

I use the slider in the inspector to make time go faster or slower πŸ€”

leaden ice
#

yes you need to actually assign it

#

TIME_INCREMENT = dayCycleSpeed

#

in Start

fiery steeple
leaden ice
#

you have too many variables here - it's confusing and overcomplicated

leaden ice
#

if you want the game to run 60X faster than real life

fiery steeple
leaden ice
#

you can and should make it how you want it to be

#

don't be constrained by whatever the code was especially if it was written by someone else

fiery steeple
leaden ice
#

why would you constrain it to -10 to 10 if you want 60?

#

So we go back to the quiestion of you have to actually explain what you want the number to mean

#

without deciding that we're just grasping at straws in the dark

fiery steeple
leaden ice
#

yes you have to say what you want that to mean

fiery steeple
#

I'm confused

leaden ice
#

if you want it to be such that 1 means 60s per real life second, then you would need to multiply it by 60.

#

e.g. TIME_INCREMENT = dayCycleSpeed * 60;

fiery steeple
#

yes that's what I want by default when dayCycleSpeed has a value of 1

leaden ice
#

then if you set it to 10, it would be 1 second in real life = 600 seconds in game (10 minutes)

fiery steeple
#

huh no, that's not what I want

#

I want when I set it to 10, it goes 10x faster, meaning the value is really low between each iteration

leaden ice
#

10 minutes IS 10x faster than 1 minute

fiery steeple
#

How is 10 minutes faster than 1 min ?

leaden ice
#

10 minutes of game time per second vs 1 minute of game time per second

#

it's faster as in the in-game clock is running faster

fiery steeple
#

oh from that point of view yes

#

so what do I have to change in my formula ?

leaden ice
#

and then you need to fix the first line of Update too

leaden ice
fiery steeple
#

like so ?

leaden ice
#

yep

#

although there's another weirdness here

fiery steeple
#

but there will still be an issue of me not being able to change speed of day at runtime as "dayCycleSpeed" is assigned at start

leaden ice
#

your code assumes that timeOfDay is a number between 0 and 24

#

also that if (timeOfDay > 24) timeOfDay = 0; line is not right - it should be timeOfDay %= 24; really

leaden ice
#
float timeIncrementPerSecond = voxelPlayEng.world.dayCycleSpeed * 60f;
timeOfDay += Time.deltaTime * timeIncrementPerSecond;```
#

and get rid of the stuff in Start

#

the other thing though is we'll need to adjust to your 24 thing

fiery steeple
#

still need to keep timeOfDay as it's the starting time of day that the game starts at

leaden ice
#

wdym

#

oh

#

sure

#

yeah

#

I meant the other stuff

fiery steeple
#

I want my game to start at 6:00 AM and not 00:00

leaden ice
#

anyway the code I gave you assumes timeOfDay is expressed in seconds

#

and there are 86400 seconds in a day

#

but you want it to be expressed in hours

#

so we would need to divide by 3600

fiery steeple
#

But wait %24 I already do that here, isn't that enough that I have to put it again in Update() ?

leaden ice
#

e.g.

float timeOfDayInSeconds = 0;

void Update() {
   float timeIncrementPerSecond = voxelPlayEng.world.dayCycleSpeed * 60f;
   timeOfDayInSeconds += Time.deltaTime * timeIncrementPerSecond;
   timeOfDayInSeconds %= 86400; // wrap the day around midnight
   float timeOfDayInHours = timeOfDayInSeconds / 3600f;
}```
#

well your days calculation doesn't make sense since you're automatically setting anything > 24 to 0 anyway

#

to be perfectly honest you could/should just be using DateTIme.

fiery steeple
#

and make it start at day 0 ? And at hour 6:00AM ?

somber nacelle
leaden ice
#
DateTime currentTime;

void Start() {
  // assuming january 1st, 2025 here
  currentTime = new DateTime(2025, 1, 1, voxelPlayEnv.world.timeOfDay, 0, 0);
}

void Update() {
  float timeScale = 60 * voxelPlayEng.world.dayCycleSpeed;
  currentTime = currentTime.AddSeconds(timeScale * Time.deltaTime);
}```
leaden ice
#

arbitrary

#

I just picked something

#

you could use TimeSpan like box said

fiery steeple
#

ok but that does mean that it takes a starting IRL date ?

leaden ice
#

yes

fiery steeple
#

why ?

leaden ice
#

because that's what DateTime represents

fiery steeple
#

So that means it will never start at day 0 πŸ€”

somber nacelle
#

if you don't need an actual date, just use a TimeSpan, you can even format it to give you Days:Hours:Minutes

fiery steeple
leaden ice
#

Here's how you would with TimeSpan:

TimeSpan currentTime;

void Start() {
  currentTime = new TimeSpan(0);
}

void Update() {
  float timeScale = 60 * voxelPlayEng.world.dayCycleSpeed;
  currentTime += TimeSpan.FromSeconds(Time.deltaTime * timeScale);
}```
leaden ice
#

Easy enough to read from too

string currentTimeString = $"Days: {currentTime.Days}, Hours: {currentTime.Hours}, Minutes: {currentTIme.Minutes}, Seconds: {currentTime.Seconds}";```
#

there's probably a nice way to use format strings with it that I'm not savvy to as well

fiery steeple
#

so I don't need my FloatToMilitaryTime() anymore ?

leaden ice
#

nope

somber nacelle
#

also calling it "MilitaryTime" is silly, it's just a 24 hour clock which much of the world uses already

leaden ice
#

well you might replace it with something like this^

fiery steeple
#

because it's wrriten as a 24 hours system

#

like for instance 2200 = 22h00 = But the US say 10 PM

somber nacelle
#

sure, it's not standard to use the 24 hour clock in the US, but still calling it "Military Time" as if it is exclusive to the military is silly and a thing that only americans do

leaden ice
#

anyway - point is - Use TimeSpan, it's nice

fiery steeple
fiery steeple
leaden ice
#

oh gosh

#

pretty sure that wasn't going to work anyway

#

it depends on exact times being reached

fiery steeple
fiery steeple
leaden ice
#

the way to do this would be to have a list of events with times attached to them, and whenever the time changes you iterate over the list and trigger all events whose time is less than the current time

fiery steeple
#

to start and end routines

leaden ice
#

and remove them as you trigger them

fiery steeple
#

and I don't want that

leaden ice
#

no it won't

#

because like I said, you remove them once you trigger them

fiery steeple
#

I'm not sure to understand

leaden ice
#

it's ok this is a totally separate issue anyway

fiery steeple
#

alright

#

Which one do I choose here ?

leaden ice
#

what does it need to represent

#

the hour of the day?

fiery steeple
#

I have no clue

leaden ice
#

it says there

fiery steeple
#

it says time in 0-24h range

leaden ice
#

it wants a string 🀒

fiery steeple
#

no above you have a float

leaden ice
#

oh - yeah it wants the hour of the day

#

you can do currentTime.TotalHours % 24

#

well you'll need to actually do

(float)currentTime.TotalHours % 24f```
fiery steeple
#

It's really slow, how can I be sure that 24 minutes IRL = 24 hours IG ?

#

Also can I put back my system that avoid printing the same value multiple times ?

leaden ice
#

just turn on Collapse in the inspector

#

er

#

in the Console

fiery steeple
#

but I will need that anyway later to avoid Invoke the same event multiple times

leaden ice
leaden ice
#

yes you can of course make a system for that

#

but I don't see that it would be an urgent need

fiery steeple
leaden ice
#

anyway the actual time won't bee the same anyway

#

the precise timings thing is a pipe dream and it will cause bugs

#

if you have a framerate hiccup that makes you skip a second, your event will not trigger

#

you should use a more robust algorithm for it

fiery steeple
#

like ?

leaden ice
#

like I mentioned above - triggering the event at the first time you see the current time is >= the scheduled time

fiery steeple
#

Isn't there a better way than that ? Like maybe not using framerate stuff and go for more precise stuff ?

leaden ice
#

not sure what you mean by that

#

you are bound to the framerate of the game, you don't have any choice about that

#

you could use FixedUpdate but that's really just a wrapper around Update doing the same kind of check I'm talking about

#

I guess if you don't feel like thinking about it, FixedUpdate is one possible choice

fiery steeple
leaden ice
#

Coroutines?

fiery steeple
#

yeah

leaden ice
#

no, coroutines are not going to help you with precise timing

#

they do the same thing I was mentioning

fiery steeple
#

don't those give precise timings when you yield new WaitForSeconds() for instance ?

leaden ice
#

no

#

not at all

#

if you do WaitForSeconds(1) it will run on the first frame after 1 second has elapsed

#

which will never be exactly 1 second

#

it will be like 1.0154 seconds or something

#

coroutines are checked once per frame

#

There's really no escaping the frame-based game loop

fiery steeple
#

mhh interesting, so your solution with >= is the best I guess ?

leaden ice
#

I wouldn't have given you my second-best idea.

fiery steeple
#

And is that the way it's done in published games too ?

leaden ice
#

absolutely

fiery steeple
#

interesting, you taught me something new today πŸ˜„

#

they should renamed that method from the coroutine to WaitForApproximativelySeconds() to be more accurate πŸ‘€

cosmic rain
#

That's true to almost everything time related in unity(and most other game engines)

#

Unless the whole logic is run on a separate thread and does something like thread sleep or yields. Which wouldn't be 100% precise either, but probably precise to the microseconds(depending on how busy the CPU is).

leaden ice
#

the fact is you can only draw things on screen when a frame happens anyway, so there's not a huge benefit to trying to do things outside of that.

fiery steeple
#

when I set the speed to 20, it skips values, is that normal ? πŸ€”

#

is it the thing we talked about just above ?

cosmic rain
#

We would need to see your current code to say anything

leaden ice
#

with speed set to 20 time is moving 1200x faster than real life

leaden ice
#

that's 20 minutes every second

#

you're bound to skip a few seconds

cosmic rain
tawny elkBOT
fiery steeple
# cosmic rain Please share !code properly next time:
private void Start()
{
    voxelPlayEnv = VoxelPlayEnvironment.instance;
    timeOfDay = voxelPlayEnv.world.timeOfDay;
    currentTime = new TimeSpan(0);
}
  
private void Update()
{
    float timeScale = 60 * voxelPlayEnv.world.dayCycleSpeed;
    currentTime += TimeSpan.FromSeconds(Time.deltaTime * timeScale);
    
    voxelPlayEnv.SetTimeOfDay((float)currentTime.TotalHours % 24.0f); // Set Time of Day
    print($"{currentTime.Days}:{currentTime.Hours}:{currentTime.Minutes}:{currentTime.Seconds}");
    //OnGameTimeChanged?.Invoke(timeOfDay); // Call the event
    

    // previousTimeOfDay = timeOfDay; // Set the current time to the previous time to avoid events firing multiple times
}  
#

the indentations is messed up on discord 😀

#

60 years since the creation of discord and something this simple is still not fixed πŸ₯²

leaden ice
#

the indentation is fine - you just started your copy paste from the p so it doesn't have any preceding space on the first line

night harness
#
public abstract class InspectorField<T> : InspectorField
{
    public override bool TrySetTargetValue(BoxedValue potentialValue)
    {
        if (potentialValue is BoxedValue<T> castedValue)
        {
            SetTargetValue(castedValue);
            return (true);
        }
        return (false);
    }
}

I can do generic type checking like this right? where if the InspectorField<T> in question is a InspectorField<string> and the BoxedValue<T> is a BoxedValue<string> ?

the answer is yes

fiery steeple
#

@leaden ice @cosmic rain @somber nacelle Thank you to all of you πŸ™‚ πŸ‘

ocean mirage
#

Hi all,
is it okay to subscribe to an unity event of a prefab with another prefab? like a preconfiguration. i feel like i got crazy bugs in it that i cant even debug.

night harness
#

no

#

prefab assets shouldn't have event subscriptions afaik

#

unless it's correctly in the context of it's own asset

#

posting relevant screenshots might help

ocean mirage
#

thx keep in mind i used a unityevent in an SO before and it worked but i wanted to try something different

#

i can try post screenshots

#

not sure what to show coz i cant find the place where it fails

#

πŸ˜„

hexed pecan
#

Oh if you wanna post code, see !code πŸ‘‡

tawny elkBOT
ocean mirage
#

aight

#

so i should send my files?

#

1 enemy should send 20 xp per death. the player always has 0 xp at start.

#

and if i kill 7 enemies it instant starts with 140xp and then adds normaly 20 per death

#

but it should look like this: 0, 20, 40, 60, 80, 100, 120, 140

#

i stop the game and restart and kill 4 enemies and get this

#

last screenshot πŸ˜„ then i kill again 5 and got this

#

i could also join a voice channel where i share a screen. thx anyway

vestal arch
ocean mirage
#

Ah makes sense

hexed pecan
# ocean mirage

First thing I noticed that you are calling this in Start: cs UpdateExperience(0);
Which adds 0 to the XP. Do you expect it to set it to 0, or are you calling that just to invoke the OnExperienceChange event?

#

I also don't see how prefabs are related here/why are you using or invoking events on the prefabs

#

Sounds like hell

ocean mirage
#

The whole thing is about communicating with objects that will get instantiated in the middle of the game

#

I try to find solutions, but its so hard to not have a reference of another gameobject to call the methods that i need

hexed pecan
#

Okay so not really prefabs, right?
Prefabs mean gameobject assets, we don't use "prefab" to describe an instantiated object

ocean mirage
#

ehhm im not sure. i instantiate enemy prefabs and a player prefab into the scene. what is it called?

hexed pecan
#

Yeah at that point it's called just a gameobject or an instance

#

I'm not trying to be pedantic, just making sure we are on the same page :p

ocean mirage
#

yeah sure np ask everything. this bug keeps me up all night

night harness
ocean mirage
hexed pecan
#

Yeah that makes sense, just making sure

ocean mirage
#

OnExperienceChange gui is subscribed on that

hexed pecan
#

"It instant starts" is confusing to me

ocean mirage
#

yes i kill 7 enemies with one shot

rotund sedge
#

where are you subscribing to OnEnemyDeath?

hexed pecan
#

I only see UpdateExperience being called from the start, where else do you call it from?

rotund sedge
#

i dont see any subscription to OnEnemyDeath aside from supposed commented code

ocean mirage
#

enemylevelcontroller.sendexperience() is subscribed on enemydeath

#

ah wait

#

nono

rotund sedge
#

it's subscribed to its own event?

ocean mirage
#

nah my bad

#

playercontroller.updatexperience

hexed pecan
#

Is that all that OnEnemyDeath does?

ocean mirage
#

i have another ondeath event in a health script that does way more earlier ofc

#

thats why i got confused at first

hexed pecan
#

Ahh so the issue is that this event on thet enemy object calls a method on the player prefab?

young yacht
#

so wait you're sending an event to instantiated objects OnEnemyDeath during runtime?

rotund sedge
#

is enemylevelcontroller for a single enemy or the controller for all enemies in the level?

ocean mirage
#

enemylevelcontroller for all that got instantiated

rotund sedge
#

so each enemy has enemylevelcontroller?

hexed pecan
#

But what does this belong to

ocean mirage
#

yes

hexed estuary
#

Hey I was told to come here to learn coding…

hexed pecan
#

The player level controller script

ocean mirage
#

mage is the player

hexed pecan
#

The prefab or an instance

rotund sedge
#

i kind of know what the problem is but dunno how to properly say it ahahaha

#

i guess the others know too already xD

young yacht
#

so when an enemy dies you get xp from them, and your problem is that you're getting too much xp?

hexed pecan
#

I think the event is calling UpdateExperience on the player prefab, not the instance

ocean mirage
#

basicly

young yacht
#

do you kill only one enemy or all of them at the same time?

ocean mirage
young yacht
ocean mirage
hexed pecan
#

The prefab is the blueprint/template that you use to instantiate new objects

rotund sedge
#

i guess what he did is create a prefab for the enemy and player. then uses the prefabs to the event thats why it shows.

hexed pecan
#

You shouldn't reference the prefab and call methods on it

young yacht
hexed pecan
#

It doesn't know to use the player instance in the scene instead

hexed pecan
ocean mirage
young yacht
#

okay so what i understand is you want to kill all of them, but get xp one by one

#

instead of getting everything at the same time

ocean mirage
#

nono

#

i try again sorry πŸ˜„

young yacht
#

complicato

rotund sedge
#

can you check:
go to your enemy prefab. then click on the mage (Player Level Controller) of the event. tell us what it pinged in the editor.

#

make sure yuo are not in play mode.

ocean mirage
# ocean mirage

it starts with 140 experience for no reason. i just had 0 and now i got 140 from killing 7 enemies but that cant be the case because if i debug, it just starts right after to give me the experience for the first kill

rotund sedge
#

sad that theres no call or something channel in this server xD

hexed pecan
#

You are instantiating the Mage into the scene, right? (Or have it in the scene to start with)

young yacht
ocean mirage
#

i instantiated for this case

young yacht
#

you need to reference the instance

ocean mirage
#

yeah it could be the case

rotund sedge
#

you instantiated but you are still using the prefab

ocean mirage
#

yes

#

coz i dont see how i can relate those gameobjects without knowing each other

young yacht
#
PlayerMage mageInstance = Instantiate(playerMageObject).GetComponent<PlayerMage>();
#

something like this gives you the instantiated script of the object

hexed pecan
#

You need to pass the player reference to the enemy when the enemy spawns

#

Or in some other way you need to have the player instance referenced in the event instead of the prefab

ocean mirage
#

but what if the player needs to know the enemy? there are 100 enemies and i need exactly one

young yacht
#

you can pass the enemy gameobject through the event

night harness
#

whatever reason the player would need to know a specific enemy would involve that communication

young yacht
#

you could have an enemy identifier, like an index or a certain name, whatever you want, send it to the player and have the player check if its the enemy you want

rotund sedge
#

if you have just one player. for now you can make the player controller as singleton.
then create an enemy spawner object. in your enemy spawner object, everytime you spawn an enemy with EnemyLevelController you reference the player.

var enemy = Instantiate(enemy);
enenmy.OnEnemyDeath(player.SendExperience);

dirty code but that would work for now.

ocean mirage
hexed estuary
#

I don’t want to be a bother but um can somebody teach me coding?? I was told to go here

young yacht
#

centralized and clean

hexed pecan
rotund sedge
#

if i'm the one doing it, and i want to decouple things, i'll use like an event bus or something. basically, enemy just invokes on enemy death without caring whoever gets it and player just listens to any event that happens.

young yacht
#

yea thats what i do

#

works nicely

ocean mirage
#

yeah

#

tahts why i also want events

#

i ahve literally not one reference for now

young yacht
rotund sedge
ocean mirage
#

i just refactored all c# events to make use of unityevents

hexed pecan
ocean mirage
#

coz i want the game designer to decide whats going on without have to go to the code

young yacht
hexed pecan
young yacht
#

if the game designer wants changes then they just refer to that file

rotund sedge
#

basically it would be like this in enemy:
EventManager.EmitEvent(OnEnemyDeath);

then in player you just subscribe:
EventManager.Subscribe(OnEnemyDeath, OnEnemyDeath);

void OnEnemyDeath(Enemy enemy) {}
young yacht
night harness
#

you aren't either what

young yacht
#

wut

#

xD

night harness
#

i said debatable because i don't think a good amount of people would agree with that advice

young yacht
#

ohh i see

night harness
#

not saying its wrong but not like a standard goto solution

young yacht
#

it would depend if the game designer knows how to code

rotund sedge
#

gets popcorn 🍿

hexed pecan
young yacht
#

i assumed he wants to make clean code so the game designer knows what's happening

#

without checking the code itself

#

he'd look at the unity editor and know

night harness
#

the point of unity events is to avoid code entirely

hexed pecan
#

I don't understand what the designer could change here in the first place

rotund sedge
#

this might be rude, but if he's a beginner, he should not think about that yet :x

ocean mirage
#

i think im not a beginner but not an expert either

hexed pecan
#

Personally, I didn't gauge you as a beginner πŸ€·β€β™‚οΈ

young yacht
night harness
#

theres ways you can get around it

#

if your psycho

ocean mirage
#

yeah thats what i learned now

#

thank you all so much

night harness
#

are you singleton pilled proto

hexed pecan
rotund sedge
#

ok. lets just say that if you cant differentiate or know the limitations of prefabs and instances, then i guess you still have a lot to learn. and making code that a designer can use is probably not one of them YET

hexed pecan
#

Because I think this should all be hard coded

young yacht
rotund sedge
#

for now, just tell your designer that he can only change the data values in scriptableobjects. and if he wants custom mechanics, just tell you, the developer.

ocean mirage
#

i actually knew the differnce between it but i thought the event makes no difference about it thats why i tried it

#

thanks all

#

u helpd me alot

young yacht
#

no problem man

#

have a good one

night harness
#

one nice comprimise is using a scriptableobject to middleman these kinds of requests if you want a mix of writing code and exposing it to game designers

#

eg.

#
public class PlayerReference : ScriptableObject
{
    public void AddExpToPlayer(int value)
    {
        MyGameManager.Instance.Player.AddExp(value)
    }
}
#

then you can pass this into the unityevent and as long as your singleton manager is setup correct and has a proper reference to the instanced player your gucci

rotund sedge
#

good compromise but somehow adds redundancy so I don't like it xD but it's probably just me :x

night harness
#

far from perfect but imo a good balance between ease to setup for programmer and ease for designer to use

steady bobcat
#

Seems kinda shit to me, editor validation and automation are the way to go to make sure things work correctly if set up by others.

ocean mirage
#

editor validation and automation
but how?

steady bobcat
#

its going to differ per project but if some component needs to be initialized/referenced somewhere when added, it can be done automatically in some way

#

I prefer to init and handle dependencies such as player, config, localisation manually without static singleton references

ocean mirage
#

i dont understand exactly how u would do it but maybe chat gpt can help me with your ideas

#

i dont like singletons either

steady bobcat
#

It can be useful to just use a static field but there may be a time when you wish to use something elsewhere and that field is no longer usable.

To avoid this you probably need the manager to initialize objects and give the references they need on Init or pass itself so they can ref this way.
e.g. Load scene -> init manager -> manager inits children and gives dependencies

ocean mirage
#

with that approach i cant really use unityevents right? i need to go back to c# events

hexed pecan
#

If the event needs to reference a scene object then yeah, you need to might as well use C# events

night harness
steady bobcat
#

unity events can be subscribed to with code but yes something not in the scene to start cant just be used

#

You probably need components ready made to perform the tasks you need without unity event stuffs

#

remember you can do whatever you want you dont have to listen to me πŸ˜†

ocean mirage
#

so in order to not have a reference of something u want to subscribe to, best thing u could do is having multiple event managers for different things

#

why is there not a better solution to that overall? maybe im blind or stupid πŸ˜„

#

i feel like programming in unity is kinda easy as a software developer but the architect stuff is way more confusing than in real life projects with spring, dotnet or other frameworks

#

im stuck so hard with this event stuff and i only want just a single solution to that, so i can keep going. coz the normal stuff like making new gameobjects and content is kinda easy

#

just ignore my cry sorry πŸ˜„
thx all ❀️

steady bobcat
#

I'm not fully understanding your use case rn but hopefully you get a solution you like.

young yacht
#

hey guys whats a nice and clean way of having the player with a trigger collider and everytime it goes through a spawn point it picks up that gameObject and sends it to a list?

#

right now i got a waveManager that contains a list of all the available spawnPoints close to the player

#

and with that player trigger i want to either add or remove from that list everytime they get close or far

#

are C# events good here? or would it eat too many resources?

steady bobcat
#

I think thats fine. The player would have an event that is invoked when it hits a spawn point?

steady bobcat
#

It could also be the other way around, the spawn point detects the hit and then tells the player to add itself

#

May be better as im not sure how reliable a moving trigger would be

young yacht
#

true and also another thing

#

this player and waveManager are singletons, so maybe a simple reference is also good? or not a good practice?

steady bobcat
#

If the spawn point has the trigger collider, it can get the component and add itself without external references

young yacht
#

only thing is i'll be adding the same script to all spawnPoints

steady bobcat
#

ofcouse

young yacht
#

i'll have quite a lof of spawn points so maybe its better if its centralized

#

but could also work well

steady bobcat
#

you have many gameobjects anyway so i dont see a problem

young yacht
#

true

#

just wanted some advice on it since i dont really know the best practices yet

steady bobcat
#

If there is 1 component that manages all of the spawnpoints for later use then that sounds fine to me.
e.g. when spawnpoint detects player, adds itself to some list with a unique id . player dies, level manager gets finds best spawnpoint with an id and does something.

#

If ids are used then this data can be saved and re loaded later

#

There are many ways to do things so have a think about your requirements and what will be best to maintain and handle in the future

young yacht
#

dont think it needs to be that complex

steady bobcat
#

Ah in that case you can probably just do a simple square distance check every x amount of time to update some pre sized collection of these points

#

(squared distance is cheaper to use as we avoid a square root)

young yacht
#

never heard of that actually

#

what would be the code for that?

steady bobcat
young yacht
#

ohh

#

i'll give it a look

#

thanks

steady bobcat
#

np. Id go with this as using triggers seems overly complex for what you described

#

this presumes though this is a radius check, a box/rect check is also cheap as its a simple min max bounds checking

regal crag
#
        {
            CrouchInput.Toggle => !_requestedCrouch,
            CrouchInput.None => _requestedCrouch,
            _ => _requestedCrouch 
        };```
If I have something like this and want to let the player to swap between toggle crouch and hold crouch, would it be good I make a separate `_requestedCrouchStyle = input.CrouchStyle switch` to dictate the swap or is there a more efficient way of implementing this
young yacht
# regal crag ``` _requestedCrouch = input.Crouch switch { CrouchIn...
void Aiming(InputAction.CallbackContext context)
    {
        if (context.performed)
        {
            isAiming = true;

            crosshairImage.sprite = crosshairFull;
            LeanTween.scale(crosshairRect.gameObject, new Vector3(0.15f, 0.15f, 0.15f), 0.3f);

            aimWeight = 1;
        } else if (context.canceled)
        {
            isAiming = false;

            crosshairImage.sprite = crosshairEmpty;
            LeanTween.scale(crosshairRect.gameObject, new Vector3(0.1f, 0.1f, 0.1f), 0.3f);

            aimWeight = 0;

            OnShootingCancelled?.Invoke();
        }
    }

ignore the shitty code but this is how i do it

#

context.performed and context.canceled

regal crag
#

lmfao

#

so just change the code into something like if(crouchChange.performed) and wrap the same code over

#

eh sounds not bad

regal crag
#

ight thanks

steady bobcat
#

you can use local functions if you want to not repeat code in a function

regal crag
#
{
        _requestedCrouch = input.Crouch switch //CrouchInput is a struct
        {
            CrouchInput.Toggle => !_requestedCrouch,
            CrouchInput.None => _requestedCrouch,
        if (_crouchSwitch && InputActions.Crouch.WasPressedThisFrame)
        {
            CrouchInput.Hold => _requestedCrouch
        }
        else if (_crouchSwitch && InputActions.Crouch.WasReleasedThisFrame)
        {
            CrouchInput.Hold => !_requestedCrouch
        }
            _ => _requestedCrouch 
        };
}```
#

something I've cooked up haven't tested it yet

deep echo
#

what exacly is the use of node scripts, up until now i only use them as some sort of storage of couple values, and pathfinding

hexed oak
#

found an ok video player for unity, but it comes with all these extra assemblies. Is there a way to chop these down or bring them in to one?

steady bobcat
#

if you want to break it sure πŸ˜†

#

its normal to split things up in to many assemblies, i use about 8 for my in project stuff

hexed oak
#

I guess I'll have to get used to it hah

#

normally I just do new projects in a separate solution and build the dll's/drop them into my project. Then I can manage cross project references outside of unity and not bloat the solution manager with dozens of projects

steady bobcat
#

its not bloat but what made you want to make things outside of the editor?

#

the projects in the sln dont actually mean anything to unity and are there to represent the different assemblies untity compiles

hexed oak
#

There's some advantages to building outside the editor and dropping them in. You can version things, and at some point decide to not support a certain project anymore without breaking it--essentially han soloing it to sit frozen until the bytes rot on the last hdd it's on

steady bobcat
#

packages can do this but if this is some lib that is not meant to be unity only, i can understand developing it externally

hexed oak
#

I met up with some of the Unity reps last year and they actually said that was a recommended action to do--which surprised me. Mostly because they had made a recommendation at all.

steady bobcat
#

good for them but im not going to do this πŸ˜† im fine with packages for such tasks

neat tundra
#

Hey all! I'm getting this error and I'm not entirely sure why it is. Its pointing to this function:

#
private void OnTriggerEnter2D(Collider2D collision) {
    if (collision.TryGetComponent(out EnemyBase enemy) == false) return;

    if (enemy.TryGetComponent(out HealthComponent enemyHealth) == false) 
      return;

    enemyHealth.TakeDamage(bulletDamage);

    penetrationCount += 1;
    if (penetrationCount >= penetrationAmount.Value) {
        _projectilePool.Release(this);
    }
}
#

and I'm really not sure why it's happening

leaden ice
#

OnTriggerEnter2D can run more than one time per object in a single physics update. For example if multiple colliders are entered in one physics frame

#

you would need some kind of like "isDead" variable to set and use that as protection here

neat tundra
#

ooh that makes sense

leaden ice
#

like if this is a bullet and it hits more than one of the enemy's colliders at once

#

it can happen

neat tundra
#

I guess an int counting the amount of times OnTriggerEnter2D() was run would be enough?

leaden ice
#

That could be a little complex because you'd need to reset it in FixedUpdate

neat tundra
#

oh true

naive swallow
leaden ice
#

Or - I guess if this thing can only ever hit one thing...

#

You really just need a bool tbh

#

unless it is supposed to hit multiple things

#

I do see the penetration count thing?

#

Couldn't you just use penetration count here?

#

e.g. change penetrationCount >= penetrationAmount.Value to penetrationCount == penetrationAmount.Value

#

that would probably fix it too

neat tundra
#

I'll try that and see if it works

#

thanks a bunch

#

In a minute of playtime it didn't happen yet, so I'm guessing its fixed! Thank you

fiery steeple
vestal arch
fiery steeple
vestal arch
#

of TimeSpan

#

but you could make new ones via its constructor i suppose

#

alternatively you could get the Hours component and switch on that? idk what you're trying to make

leaden ice
#

yes there's an existing instance

#

it's the parameter to this function

#

but this problem won't be solved by a switch alone

vestal arch
#

no, i mean for the thing to match against in the switch

leaden ice
#

oh - yeah - you could do it that way

#

or just have each one have a time of day expressed elsewise.

#

.Hours and .Minutes definitely exist on TimeSpan though so IDK what @fiery steeple is saying

fiery steeple
#

Like I send it in this event here, but I'm confused why here (so in another class) I can write currentTimeOfDay.Hours, etc... while in the other class I can't πŸ€” ?

vestal arch
#

wdym you can't?

leaden ice
#

Yeah what is stopping you?

#

probably because you're in a switch statement?

leaden ice
#

because that doesn't make sense

fiery steeple
#

@vestal arch ☝️

leaden ice
#

it would be like switch (time.Hours) { case 5: }

fiery steeple
#

Oh

leaden ice
#

you need constants for the switch cases

#

but this is really not going to work well as a switch

fiery steeple
#

oh yeah because of the thing we talked about yesterday, aka the imprecision ?

leaden ice
#

yes

fiery steeple
#

so I have to go throug a classical if statement ?

leaden ice
#

no

#

YOu should make like an Event class

#

which has the event info and the time

fiery steeple
#

I don't understand πŸ€”

leaden ice
#

then one way you could do this is like:

// declared outside
HashSet<Event> alreadySeenEventsToday = new();

foreach (Event evt in allDailyEvents) {
  if (currentTime.Hours >= evt.TimeOfDay && !alreadySeenEventsToday.Contains(evt)) {
    alreadySeenEventsToday.Add(evt);
    ProcessEvent(evt);
  }
}```
#

where you put all the events in a list called allDailyEvents

#

effectively we would be checking all the events to see if the time of day they happen at has arrived yet, and if it has, put it in a set to track which ones we've seen today (so we only process them once per day), and process them

#

so basically if you had like:

    {
      name: "breakfast",
      timeOfDay: 6.5 // 6:30am
    },
    {
      name: "lunch", 
      timeOfDay: 13 // 1pm
    }
  ]```
#

then lets say 6:30 rolls around, the current time might be like 6.55 (this is what you'd get from currentTime.Hours). So you would see that breakfast happens now, and you would add it to the set of things you already saw so you would ignore it going forward.

naive swallow
# fiery steeple doesn't show up πŸ€”

A switch statement only checks ==. You are checking if time is equal to a specific thing. The thing you put in the case needs to be something that time could be == to. You can't use any other comparators for a case

vestal arch
naive swallow
#

You can use > and whatnot for a timespan, but not in a switch statement

vestal arch
naive swallow
#

Is that available on the version of C# that Unity uses?

vestal arch
#

yeah, just tested

fiery steeple
naive swallow
#

At one point I remember lamenting that I couldn't use the inline switch statement, but admittedly that was a while ago...

vestal arch
#

uh, that's a switch expression?

naive swallow
#

I just assumed nothing ever improves and that we were stuck without them forever

vestal arch
#

fair given the state of the runtime situation lol

leaden ice
fiery steeple
vestal arch
#

there's no Event keyword there

#

that's just a type

leaden ice
fiery steeple
#

I'm talking about this

vestal arch
#

(fyi: keywords are typically in lowercase)

#

yes, that's not a keyword

fiery steeple
vestal arch
#

that's a type

leaden ice
fiery steeple
vestal arch
#

sure

fiery steeple
vestal arch
#

yeah just make a struct for it and serialize a list of that struct

leaden ice
fiery steeple
leaden ice
#

the one we're talking about

#

Event

#

or DailyRoutineEvent

#

a list of them

fiery steeple
#

you don't understand me I think

#

here you have written the data as k,v pair

leaden ice
#

Yes - i was just expressing the information to you

#

in reality the information would live in a class or struct in a list

fiery steeple
#

so what's the best type for that

leaden ice
#

A custom type called Event or DailyRoutineEvent containing a start time and an event name/identifier of some sort

#

as we have been discussing

#

super simple example:

public class DailyRoutineEvent {
  public string Name;
  public float TimeOfDay; // In fractional hours [0, 24) e.g. a value of 6.5 here would mean 6:30AM, and a value of 13 would be 1PM
}```
fiery steeple
#

oh I'm dumb πŸ€¦β€β™‚οΈ

#

and isn't it possible to not write the hours as float but as Military time ? πŸ‘€ Because I have to do math if it's not 6:00 or 6:30 πŸ‘€

vestal arch
#

should probably be a struct, eh?

vestal arch
#

would have to separate the minutes or use a string

fiery steeple
vestal arch
#

using a string is not particularly safe since it's way more flexible

leaden ice
vestal arch
#

bordering into too flexble for this kind of thing

leaden ice
#

Not sure what math you mean

#

you'd have to parse the string into a number anyway

vestal arch
#

yeah what math would you have to do?

#

i guess to display it?

fiery steeple
#

Like this, where the 2 firts numbers = minutes, then 2 hours number, then 2 days number

leaden ice
#

there's no need for this swtich anymore

#

remember we're discussing replacing it entirely

vestal arch
#

what happens if you accidentally add a space

#

what happens if you accidentally add an invisible character in the code

#

these are all silent errors

#

you get bugs with no trace of where it came from or why it happened

#

a number type gives you a narrower space of possibilities, which removes these string issues

fiery steeple
leaden ice
#

you would instead have a completely different switch somewhere based on the event name. e.g.

public void perform(DailyRoutineEvent evt) {
  switch (evt.Name) {
    case: "breakfast":
      Debug.Log("You eat a hearty meal!");
  }
}```
leaden ice
#

what is the math for

#

all you do is if (currentTime.Hours > evt.TimeOfDay)

fiery steeple
vestal arch
leaden ice
#

I see

fiery steeple
#

instead of 7 AM

leaden ice
#

then yes it's just 50/60

fiery steeple
#

hence math πŸ‘€

vestal arch
#

i mean personally that's not too big of an issue, worst case could just stick to .5/.25/.75

leaden ice
#

You could write one function to parse a string and convert it to the float, sure

#

that's not a big deal

vestal arch
#

alternatively, could use like, actual military time

#

ie, 6:50 => 650

leaden ice
#

you can even use TimeSpan.Parse for it

#

so again no math really needed

fiery steeple
vestal arch
#

not as strings though

#

(also what you described is not military time...)

leaden ice
#

the string, if you choose to use it, would just be for getting data into the system. It wouldn't be used during the actual processing.

fiery steeple
vestal arch
#

it's reversed

fiery steeple
#

how ?

vestal arch
#

military time is hours before minutes

fiery steeple
#

000700 = 0 days, 7 hours, 0 minutes

vestal arch
#

and what's 010203?

lyric veldt
#

hey guys, is it possible to change the cinemachine gain value with code. I found the reference here but I can’t access it

hidden compass
vestal arch
hidden compass
#

ahh, confusing.

#

why not just use two types?

#

day, hour

vestal arch
#

Vector3Int of d,h,m

lyric veldt
#

Anyone?

naive swallow
fiery steeple
hidden compass
hidden compass
#

not familiar with the exact property tho.. CinemachineInputAxisController.X maybe?

hidden compass
# lyric veldt Ok I will try that
using Unity.Cinemachine;
using UnityEngine;

public class TESTCINEMACHINE : MonoBehaviour
{
    public CinemachineInputAxisController myAxisController;
    public float desiredGain;


    private void Update()
    {
        if(Input.GetKeyDown(KeyCode.Space))
        {
            ChangeAxisGain();
        }
    }

    void ChangeAxisGain()
    {
        foreach(var controller in myAxisController.Controllers)
        {
            if(controller.Name == "Look Orbit X")
                controller.Input.Gain = desiredGain;
        }
    }
}``` after some fiddling i found something that works..
#

just gotta make sure the names are exact

#

couldn't find any alternative method.. Cinemachine always hard to work with imo when ur hunting up properties and how to modify things.. just trial and error for me

#

in ur case not sure it'd be "Look X (Pan)" or what.. i'd just test you can probably debug all the different names as well to find the right one

hidden compass
#
        foreach(var controller in myAxisController.Controllers)
        {
            Debug.Log(controller.Name);
        }```
#

yup u can debug the names to find the correct ones for u πŸ‘

lyric veldt
#

It work now

hidden compass
#

np πŸ‘

lyric veldt
#

Ty

hidden compass
#

ill have to remember to always try finding Controllers first when using cinemachine components

#

i think this is the 2nd time its played out that way

somber nacelle
#

they probably would have found this sooner had they actually looked at the type they took a cropped screenshot of that contained the field they wanted to modify

languid hound
#

Is there a preprocessor directive for determining whether the current build is a developer build in Unity 6?

#

I can find the DEBUG symbol but DEVELOPMENT_BUILD isn't one that's popping up

somber nacelle
languid hound
#

Weird intellisense doesn't pick it up but yeah it does work

#

Thank you

vestal arch
languid hound
#

Yuck

naive swallow
languid hound
#

Lmao

vestal arch
#

so this is syntactically fine

#

it just says x as an int won't match

#

i hate it so much

naive swallow
chilly surge
#

Pattern matching with operators is more useful with doing nested matches, less so about direct usage.

vestal arch
#

it feels wrong

chilly surge
#

Eg someList is { Count: > 0 } is an alternative to someList != null && someList.Count > 0.

#

There's not really a point in using someInt is > 0 directly.

somber nacelle
#

unless you want to check a range then you can do someInt is > 0 and < 3

umbral vigil
#

does anyone know how to fix this problem? i tried removing the 2D part at the end of "forcemode" but that doesnt work either

somber nacelle
#

even if you're trying to use the 3d ForceMode, you still have to spell it correctly. although if you are working in 2d then that force mode simply does not exist

umbral vigil
#

ah, that explains it

somber nacelle
#

also make sure your !IDE is configured so you don't make silly spelling mistakes and have access to intellisense which can show you the available members of a type πŸ‘‡

tawny elkBOT
somber nacelle
#

it is also required to receive help here

umbral vigil
#

oh okay, thank you

rustic dagger
#

Okay so I've been making a custom "debug" system, where I draw custom text gizmos with OnDrawGizmos, but, this limits me. I need a way to call a custom function like "OnDrawGizmos" but WITHOUT the need for gizmos to be enabled in the scene view
(OnDrawGizmos needs gizmos to be enabled in order for it to run, I don't want to have to have gizmos enabled in order to run my custom code)

#

I want my system to run in editor btw, that's why I use OnDrawGizmos

night harness
#

Why don’t you want gizmos enabled

rustic dagger
night harness
#

using Handles and other stuff

rustic dagger
young tapir
#

It would definitely be better to look into a custom alternative, maybe even TMPro if you're just using text Dunno

night harness
young tapir
#

It being editor only doesn't really stop you from using TMP

rustic dagger
# young tapir You *can* disable gizmos for specific classes in the dropdown

So here's what I do, whenever something wants to debug a text, I spawn a gameobject and add a 3D TMP text component on it, make the name of the gameobject something to do with instanceID of the gameobject we're trying to debug on, and bam, it works. (theres some other stuff too but whatever)

Problem, where do I tell the game I want to debug, can't be in OnDrawGizmos, because that only runs when gizmos are enabled, but still needs to run in editor. Disabling individual gizmos is kinda annoying tho lol

#

I looked into editor scripts and found Handles.Label, but again, only works when gizmos are enabled. (as far as I can tell)

night harness
#

at the end of the day its gonna be hard to get around making gizmos without turning them on

young tapir
#

If you need custom behaviour across all (or most) of your scripts.. You could make your own MonoBehaviour base class that handles it CatYes

rustic dagger
night harness
#

they aren't gizmos because you don't want them to be

night harness
#

what your doing is what gizmos are

rustic dagger
night harness
#

which is what your doing with 3d text components yeah

#

but it's not what Unity's made to handle this solution

#

if you wanna do editor only in scene debug text "right" all answers are gonna point towards gizmos

rustic dagger
young tapir
#
public class BaseBehaviour : MonoBehaviour
{
    public virtual void OnDebug()
    {
        // Call this wherever
    }
}```

Or use an interface to add it
#
public interface IDebuggable
{
    public void OnDebug();
}
public class SomeClass : MonoBehaviour, IDebuggable
{
    public void OnDebug()
    {
        
    }
}```
rustic dagger
#

Okay I know how to do that, yeah, but how could this run every frame in edit mode.

night harness
#

you'd need to have a manager checking if the game is in editor mode and if it is calling that on all those objects

young tapir
#

Either ExecuteInEditMode + Update, or a custom editor

#

Or a neat custom attribute that compacts that

rustic dagger
#

Which one's the cleanest lol

#

I'm new to editor scripts btw

young tapir
#

Probably an attribute

rustic dagger
#

I've always been curious on how attributes work, so I'd like to learn.

young tapir
rustic dagger
#

Really appreciate the help btw lol

young tapir
#
[InitializeOnLoad]
public static class EditorUpdater
{
    EditorUpdater()
    {
        EditorApplication.update += Update;
    }

    protected static void GlobalUpdate()
    {
         
    }
}

[AttributeUsage(Method)]
public class UpdateInEditor : Attribute { }```
#

Written from memory, probably not the most accurate, but you get the idea

#

I would recommend doing some research into C# attributes, reflection (to get attributes in monoBehaviours, infrequently) and EditorApplication

rustic dagger
#

Alright I think I got this, thanks for the help!

rustic dagger
#

I might have done reflection wrong I legit have no clue lol

young tapir
#

Static classes can't have non-static methods, either.

#

Plus passing this, then using GetType just finds all the methods in that class, not everything using it

#

And, you definitely do not want to do that in Update

rustic dagger
#

Okay well yeah that's why I can't get it to work with static, other than that tho I don't really know what I'm doing with these, educate me lol

young tapir
#

Try FindObjectsByType<MonoBehaviour>(), instead of an object param. I'd try it in EditorApplication.focusChanged, so it refreshes every now and then, or find a way to do it manually, or whenever a component is added, not sure how that works.

Then, for every method with the attribute, add it to a collection, then loop through that collection in Update and call the methods

rustic dagger
young tapir
#

If you're using an attribute, you need to check if the type has a method that uses the attribute, then store a list of methodinfo

#

I am just about to go to sleep

rustic dagger
young tapir
#

Google is your friend CatYes

hardy grail
#

Anyone know any good coding bootcamps?

lean sail
tawny elkBOT
#

:teacher: Unity Learn β†—

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

hardy grail
#

And it’s actual class

lean sail
#

not sure what you really intend to get from a unity bootcamp. "certificates" from coding bootcamps have less value than toilet paper.

cosmic rain
# hardy grail I more so meant ones you could get like certificates for?

Honestly, certificates don't mean much in software development world. If you have 10 certificates and another person has 0, but has several sample projects in their portfolio, they have higher chance of being hired than you.
Focus on learning, improving your skills and building something you can actually show off.

#

Unless you're just collecting certificates as a hobby

hardy grail
hardy grail
cosmic rain
cosmic rain
#

Even if it's not successful, it is still a great achievement

hardy grail
#

Yeah that’d probably be a good way to practice

#

The bootcamps I’ve found are cool and all but they really just tell you what the stuff means with no real way of studying it or like homework or smthn

#

I’ll try and figure out some smaller project ideas and build up from there

lean sail
lean sail
# hardy grail Man I’m just asking

πŸ€·β€β™‚οΈ and I replied. It's really not clear if you're looking for something unity related, and this channel is purely for unity discussions.

lean sail
#

Doing small projects will help you learn and still can be added to your resume, but even people with experience or degrees are struggling.

night harness
#

I've got diplomas and my portfolio has multiple finished small scale games and a mod that managed to get 10mil+ downloads and still no bites from any studios

#

its brutal out there rn

cosmic rain
#

I guess it depends on where you look for work and what kind of position you're aiming for.

night harness
#

forsure, although my experience includes junior work in a remote, global based context aswell

#

game-jam style scoped projects are really nice for portfolio though

lean sail
cosmic rain
#

Even before that, I managed to get a job in mobile app related company as well.

#

So I really think it depends on the area, what you have to show and how to present yourself.

#

I imagine in America, especially at major cities it's probably more difficult

lean sail
#

Interesting, yea that might be more of a regional thing then. That would be extremely rare in america/canada

cosmic rain
night harness
#

I might be going crazy I cannot see it

cosmic rain
night harness
#

when

cosmic rain
#

Oh, lol, sorry.

#

3 years ago or so now.

night harness
#

ah fair

#

still fairly uncommon where I live then but only asking because from what I know since COVID stuff has dramatically changed (not just necessarily due to COVID but as a catalyst to other big reasons)

hardy grail
night harness
#

I've had a lot of people mention anecdotes obtained from before the big wave

hardy grail
#

Well tbh anywhere else sounds better than doodoo Texas

cosmic rain
#

I imagine with so many big tech companies in there, they wouldn't hire anyone with less that 50+ years of C++ experienceπŸ˜…

hardy grail
night harness
#

I think in most major cities due to the big mixups at major studios and general mass amount of layoffs the pool for applicants is so huge that the experience levels in supply far surpass the expected demand

hardy grail
#

Honestly I think it’s just rough for everyone atp

night harness
#

In Aus right now you have to be mid (aside from in-studio experience) to even be considered for junior

hardy grail
#

Except maybe if you’re an engineer or smthn

swift falcon
#

Hey guys I am going to make a save/load system using json. I was wondering what I should do about gameobjects that I spawn in with a script that need to be saved?
So stuff like bullets or something

cosmic rain
swift falcon
cosmic rain
trim schooner
#

this is a code channel, pls delete your question from here and ask the publisher of that asset.

azure frost
#

ok

#

Donezo

dull temple
#

What's "nunit" and how do I delete this trash from getting auto included? Ever since I upgraded to unity 6 the auto include for system.collections is replaced with "NUnit.Framework;"

last quarry
dull temple
#

my scripts are literally created by "new monobehaviour script" which to be exact creates a class that derives from monobehaviour

#

and in case it's still ambiguous, monobehaviour is the unity's class that's been there since many years

#

and in case you still doubt, unity as in game engine that's related to this discord

last quarry
#

No need to be rude

vestal arch
dull temple
dull temple
last quarry
#

Well if it's including NUnit it sounds like someone messed up

dull temple
last quarry
#

Might need to do it as admin, since Unity installs in Program Files

fiery steeple
#

i need to create a drop down menu in the inspector with the 24 hours of the day (+ the half of it), is there a better way than writting them all one by one ? Maybe there's something in the TimeSpan class to do that ?

This is what I want to display in the drop down list in the inspector :

  • 00:00
  • 00:30
  • 01:00
  • 01:30
  • 02:00
  • ....
  • 23:00
  • 23:30

Like I want to have that inside a struct that I want to use in a Scriptable Object that will appear in the inspector when I select it
Like I have something like this right now, but I used "TimeSpan" for now but I think it's not the right answer but it's just there to give you an idea of what I'm going for

fiery steeple
last quarry
#

Combined with propertydrawer of course

fiery steeple
vestal arch
last quarry
#

The first is for string formatting

steady bobcat
#

same as doing i.ToString("00");

regal crag
#

it should be slowed down due to gravity

fiery steeple
#

@vestal arch @last quarry @steady bobcat Thanks πŸ‘ Isn't there a way to do that with TimeSpan, as in a sense I still need to compare those to TimesSpan from my previous code to check if we're between the start and end of those times to call an event πŸ€” ?

steady bobcat
steady bobcat
last quarry
#

Well your actual serialized value would be an int I guess (position in the list)

steady bobcat
#

Remember you can serialize the time as unix ms as a long

#

you can use DateTimeOffset to convert to and from easily

#

If anyone says save it as a string i will throw a shoe at you πŸ‘ž

last quarry
steady bobcat
#

πŸ‘ž i like unix ms too much

vestal arch
#

save it in unix ms but as a string

fiery steeple
#

Wait that's kinda complex because in my case there's a shift that needs to happen as IRL secs = IG minutes

steady bobcat
#

im sure you can figure out the maths for going from MS -> S -> M -> H...

#

Unix MS is more for storing a specific date + time than some amount of time

#

And its worth noting that DateTime/DateTimeOffset and TimeSpan can all be used together quite easily

naive swallow
wind sluice
#

Hey @steady bobcat sorry to ping just remember you helping me the other day, I got splines working with the road in spline extrude but why do the ends of the road round themselves instead of staying flat? Or maybe it curves I guess? Also was curious if you knew about a good double sided shader or a good asset pack possibly already bringing in this feature?

steady bobcat
#

and there is probably some setting for rounding the ends by some amount?

cyan granite
#

does anyone know how to fix cursor lock not working unless I click in the game window when a new scene is loaded from a different scene (when the project builds).

I have two scene Title and Sandbox.

When I click on a UI button to load the sandbox scene, the mouse isn't is focus and I need to hit the window's key before it becomes in focus again.

using UnityEngine;
using System.IO;
using UnityEngine.SceneManagement;

namespace Title {

    public class TitleMenu : MonoBehaviour {

        // public string NewGameString;

        public void ConinueGameButton() { }

        public void NewGameButton(string NewGameString) {
            SceneManager.LoadScene(NewGameString);
        }

        public void SandboxButton(string SandBoxString) {
            // I'm loading the sandbox scene here
            // cursor should be locked at the start of the scene
            SceneManager.LoadScene(SandBoxString);
        }

        public void QuitGameButton() {
            Application.Quit();
        }
    }
}

this is attached to a gameObject in the sandBox scene.

using UnityEngine;
using System.Collections;

public class OnStartCursorLocker : MonoBehaviour
{
    [SerializeField] private bool lockCursorOnStart = true;
    [SerializeField] private CursorLockMode lockMode = CursorLockMode.Locked;
    [SerializeField] private bool hideCursor = true;

    private void Awake() {
        StartCoroutine(InitializeCursor());
    }

    private IEnumerator InitializeCursor() {
        for (int i = 0; i < 3; i++){
            yield return new WaitForEndOfFrame();
        }

        if (lockCursorOnStart) {
            ApplyCursorSettings();
        }
    }

    private void OnApplicationFocus(bool hasFocus) {
        if (hasFocus) {
            StartCoroutine(ReapplyCursorSettings());
        }
    }

    private IEnumerator ReapplyCursorSettings() {
        for (int i = 0; i < 3; i++) {
            yield return new WaitForEndOfFrame();
        }

        if (lockCursorOnStart) {
            ApplyCursorSettings();
        }
    }

    private void ApplyCursorSettings() {
        Cursor.lockState = lockMode;
        Cursor.visible = !hideCursor;
       //  Debug.Log($"Applied cursor: {Cursor.lockState}, Visible: {Cursor.visible}");
    }
}

I even went into the script execution order and placed the OnStartCursorLocker at -1 (right before the Cinemachine cod) but it still had no effect.

wind sluice
steady bobcat
tender willow
#

!code

tawny elkBOT
languid hound
#

Is there a way to get scripting defines to function in the IDE?

somber nacelle
#

is your IDE configured? if so then they should work

languid hound
#

It should be as the .csproj is recognized as Assembly-CSharp and not a miscellaneous file

#

Maybe I'm missing something. Unity didn't try to recompile when I defined a symbol though. Not sure if I'm missing something but it feels like it should

#

Ah wait no sorry I made an incredibly dumb slip-up

#

I spent so much time on my custom build profile that I forgot to switch to it lol

#

Okay THIS is annoying is there a way to turn this off

#

It's nice that it's smart like that but unfortunately that's not what I want

#

It's saying the code is unreachable but I don't want it to point that stuff out because of the symbol

quartz folio
#

Why not put it in an #else?

somber nacelle
#

well it is unreachable in your current profile. you can probably use a pragma to disable that warning inline though

#

or yea, an else

languid hound
#

I suppose that works yeah

#

Unfortunately that causes this

#

I suppose it's again doing what it's meant to because it's the defines have been configured

somber nacelle
#

move the endif up a line

languid hound
#

Oh crap

#

Still greys out the code which wont be used which I don't want

#

Generally speaking I just want a way to mask out code for builds that aren't developer builds

somber nacelle
#

well yeah, that's how conditional compilation works. that code will not be compiled in the current build profile so it is greyed out

languid hound
#

It'd be nice if I had intellisense and such while working on it or something that wont be compiled but I can work with that

steady bobcat
#

#if DEBUG

#

is defined in editor and dev builds

#

UNITY_EDITOR for editor only

fiery steeple
#

Tried to have that method to do the loop inside an SO but as SO aren't gameobjects on their own that are directly in the hierarchy / world, it can't execute its constructor that would call that method to generate all the 24 hours

somber nacelle
#

show what you tried for the property drawer since that would be how you get the inspector dropdown menu you said you wanted

somber nacelle
#

nowhere here are you doing anything at all with a property drawer. also !code

tawny elkBOT
fiery steeple
# somber nacelle nowhere here are you doing anything at all with a property drawer. also !code

better ?

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

[CreateAssetMenu(fileName = "SO_DailyTasks", menuName = "ScriptableObjects/SO_DailyTasks")]
public class SO_DailyTasks : ScriptableObject
{
    [SerializeField] private List<DailyTask> task;
    [SerializeField] private List<string> time;

    public SO_DailyTasks()
    {
        AddAllHours();
    }
    
    private void AddAllHours()
    {
        for (int i = 0; i < 24; i++) {
            time.Add($"{i:00}:00");
            time.Add($"{i:00}:30");
        }
    }
}

[Serializable]
public struct DailyTask
{
    private EN_DailyRoutine name;
    private TimeSpan startTime;
    private TimeSpan endTime;
}
safe flame
#

where the drawers at doe

somber nacelle
#

sure, but again, you're not doing anything with a property drawer here so i don't know what you are expecting

fiery steeple
#

I don't know πŸ€·β€β™‚οΈ I'm not sure to understand drawers properly

somber nacelle
#

have you done any research about them? or even read the page that was linked to you?

fiery steeple
#

can I put an SO here ?

#

alright

somber nacelle
#

however you probably want the property drawer for your DailyTask type instead

fiery steeple
#

oh

swift falcon
#

Just a tip guys, when should I use public vs [serializefield] private

vestal arch
#

it's a stylistic choice, choose one and stick with it

#

in general you shouldn't expose all your fields to every other class when that's unnecessary

somber nacelle
#

yeah the "ideal" would be no public fields unless absolutely necessary and just use public properties to expose things to other objects if they need it

naive swallow
swift falcon
#

Ok cool